File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Sources/_StringProcessing/Engine Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -139,8 +139,12 @@ extension Processor {
139139
140140 self . registers. reset ( sentinel: searchBounds. upperBound)
141141
142- self . savePoints. removeAll ( keepingCapacity: true )
143- self . callStack. removeAll ( keepingCapacity: true )
142+ if !self . savePoints. isEmpty {
143+ self . savePoints. removeAll ( keepingCapacity: true )
144+ }
145+ if !self . callStack. isEmpty {
146+ self . callStack. removeAll ( keepingCapacity: true )
147+ }
144148
145149 for idx in storedCaptures. indices {
146150 storedCaptures [ idx] = . init( )
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ extension Processor {
4141
4242 // MARK: writeable, resettable
4343
44+ var isDirty = false
45+
4446 // currently, useful for range-based quantification
4547 var ints : [ Int ]
4648
@@ -58,17 +60,22 @@ extension Processor.Registers {
5860 }
5961 subscript( _ i: IntRegister ) -> Int {
6062 get { ints [ i. rawValue] }
61- set { ints [ i. rawValue] = newValue }
63+ set {
64+ isDirty = true
65+ ints [ i. rawValue] = newValue
66+ }
6267 }
6368 subscript( _ i: ValueRegister ) -> Any {
6469 get { values [ i. rawValue] }
6570 set {
71+ isDirty = true
6672 values [ i. rawValue] = newValue
6773 }
6874 }
6975 subscript( _ i: PositionRegister ) -> Input . Index {
7076 get { positions [ i. rawValue] }
7177 set {
78+ isDirty = true
7279 positions [ i. rawValue] = newValue
7380 }
7481 }
@@ -128,6 +135,9 @@ extension Processor.Registers {
128135 }
129136
130137 mutating func reset( sentinel: Input . Index ) {
138+ guard isDirty else {
139+ return
140+ }
131141 self . ints. _setAll ( to: 0 )
132142 self . values. _setAll ( to: SentinelValue ( ) )
133143 self . positions. _setAll ( to: Processor . Registers. sentinelIndex)
You can’t perform that action at this time.
0 commit comments