Skip to content

Commit 024cc5b

Browse files
committed
wip: more refactoring
1 parent bd7d7c4 commit 024cc5b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Sources/_StringProcessing/Engine/MEQuantify.swift

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ extension Processor {
9191
assert(payload.quantKind == .eager
9292
&& payload.minTrips == 0
9393
&& payload.extraTrips == nil)
94+
_doRunEagerZeroOrMoreQuantify(payload)
95+
}
9496

97+
// NOTE: So-as to inline into one-or-more call, which makes a significant
98+
// performance difference
99+
@inline(__always)
100+
mutating func _doRunEagerZeroOrMoreQuantify(_ payload: QuantifyPayload) {
95101
guard let next = _doQuantifyMatch(payload) else {
96102
// Consumed no input, no point saved
97103
return
@@ -110,30 +116,21 @@ extension Processor {
110116
savePoints.append(makeQuantifiedSavePoint(rangeStart..<rangeEnd, isScalarSemantics: payload.isScalarSemantics))
111117
}
112118

113-
/// Specialized quantify instruction interpreter for +
119+
/// Specialized quantify instruction interpreter for `+`
114120
mutating func runEagerOneOrMoreQuantify(_ payload: QuantifyPayload) -> Bool {
115121
assert(payload.quantKind == .eager
116122
&& payload.minTrips == 1
117123
&& payload.extraTrips == nil)
118-
var savePoint = startQuantifierSavePoint(
119-
isScalarSemantics: payload.isScalarSemantics
120-
)
121-
while true {
122-
let next = _doQuantifyMatch(payload)
123-
guard let idx = next else { break }
124-
currentPosition = idx
125-
savePoint.updateRange(newEnd: currentPosition)
126-
}
127124

128-
if !savePoint.isQuantified {
125+
// Match at least once
126+
guard let next = _doQuantifyMatch(payload) else {
129127
signalFailure()
130128
return false
131129
}
132-
// The last save point has saved the current position, so it's unneeded
133-
savePoint.shrinkRange(input)
134-
if savePoint.isQuantified {
135-
savePoints.append(savePoint)
136-
}
130+
131+
// Run `a+` as `aa*`
132+
currentPosition = next
133+
_doRunEagerZeroOrMoreQuantify(payload)
137134
return true
138135
}
139136

0 commit comments

Comments
 (0)