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 {
139
139
140
140
self . registers. reset ( sentinel: searchBounds. upperBound)
141
141
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
+ }
144
148
145
149
for idx in storedCaptures. indices {
146
150
storedCaptures [ idx] = . init( )
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ extension Processor {
41
41
42
42
// MARK: writeable, resettable
43
43
44
+ var isDirty = false
45
+
44
46
// currently, useful for range-based quantification
45
47
var ints : [ Int ]
46
48
@@ -58,17 +60,22 @@ extension Processor.Registers {
58
60
}
59
61
subscript( _ i: IntRegister ) -> Int {
60
62
get { ints [ i. rawValue] }
61
- set { ints [ i. rawValue] = newValue }
63
+ set {
64
+ isDirty = true
65
+ ints [ i. rawValue] = newValue
66
+ }
62
67
}
63
68
subscript( _ i: ValueRegister ) -> Any {
64
69
get { values [ i. rawValue] }
65
70
set {
71
+ isDirty = true
66
72
values [ i. rawValue] = newValue
67
73
}
68
74
}
69
75
subscript( _ i: PositionRegister ) -> Input . Index {
70
76
get { positions [ i. rawValue] }
71
77
set {
78
+ isDirty = true
72
79
positions [ i. rawValue] = newValue
73
80
}
74
81
}
@@ -128,6 +135,9 @@ extension Processor.Registers {
128
135
}
129
136
130
137
mutating func reset( sentinel: Input . Index ) {
138
+ guard isDirty else {
139
+ return
140
+ }
131
141
self . ints. _setAll ( to: 0 )
132
142
self . values. _setAll ( to: SentinelValue ( ) )
133
143
self . positions. _setAll ( to: Processor . Registers. sentinelIndex)
You can’t perform that action at this time.
0 commit comments