@@ -34,7 +34,7 @@ extension Processor {
3434 currentPosition = next
3535 return true
3636 case ( _, 1 , nil ) :
37- guard let ( next, savePointRange) = input. runEagerOneOrMoreQuantify (
37+ guard let ( next, savePointRange) = input. runOneOrMoreQuantify (
3838 payload,
3939 asciiBitset: asciiBitset,
4040 at: currentPosition,
@@ -67,14 +67,14 @@ extension Processor {
6767 return true
6868 case ( _, 0 , 1 ) :
6969 // FIXME: Is this correct for lazy zero-or-one?
70- let ( next, save ) = input. runZeroOrOneQuantify (
70+ let ( next, savePointRange ) = input. runZeroOrOneQuantify (
7171 payload,
7272 asciiBitset: asciiBitset,
7373 at: currentPosition,
7474 limitedBy: end)
75- // Also, we should assert same answer as runGeneralQuantify...
76- if save {
77- savePoints . append ( makeSavePoint ( resumingAt : currentPC + 1 ) )
75+ if let savePointRange {
76+ savePoints . append ( makeQuantifiedSavePoint (
77+ savePointRange , isScalarSemantics : payload . isScalarSemantics ) )
7878 }
7979 currentPosition = next
8080 return true
@@ -163,7 +163,7 @@ extension String {
163163 maxTrips = UInt64 . max
164164 }
165165
166- return _runEagerNOrMoreQuantify (
166+ return _runNOrMoreQuantify (
167167 payload,
168168 minTrips: minTrips,
169169 maxTrips: maxTrips,
@@ -180,7 +180,7 @@ extension String {
180180 limitedBy end: Index
181181 ) -> ( Index , savePointRange: Range < Index > ? ) {
182182 assert ( payload. minTrips == 0 && payload. maxExtraTrips == nil )
183- guard let res = _runEagerNOrMoreQuantify (
183+ guard let res = _runNOrMoreQuantify (
184184 payload,
185185 minTrips: 0 ,
186186 maxTrips: UInt64 . max,
@@ -198,7 +198,7 @@ extension String {
198198 ///
199199 /// NOTE: inline always makes a huge perf difference for zero-or-more case
200200 @inline ( __always)
201- fileprivate func _runEagerNOrMoreQuantify (
201+ fileprivate func _runNOrMoreQuantify (
202202 _ payload: QuantifyPayload ,
203203 minTrips: UInt64 ,
204204 maxTrips: UInt64 ,
@@ -207,7 +207,7 @@ extension String {
207207 limitedBy end: Index
208208 ) -> ( Index , savePointRange: Range < Index > ? ) ? {
209209 assert ( minTrips == payload. minTrips)
210- assert ( minTrips + ( payload. maxExtraTrips ?? UInt64 . max - minTrips) == maxTrips)
210+ assert ( minTrips + ( payload. maxExtraTrips ?? ( UInt64 . max - minTrips) ) == maxTrips)
211211
212212 // Create a quantified save point for every part of the input matched up
213213 // to the final position.
@@ -328,7 +328,7 @@ extension String {
328328 ) -> ( Index , savePointRange: Range < Index > ? ) ? {
329329 assert ( payload. maxExtraTrips == nil )
330330
331- return _runEagerNOrMoreQuantify (
331+ return _runNOrMoreQuantify (
332332 payload,
333333 minTrips: payload. minTrips,
334334 maxTrips: UInt64 . max,
@@ -338,17 +338,15 @@ extension String {
338338 }
339339
340340 /// Specialized quantify instruction interpreter for `+`
341- fileprivate func runEagerOneOrMoreQuantify (
341+ fileprivate func runOneOrMoreQuantify (
342342 _ payload: QuantifyPayload ,
343343 asciiBitset: ASCIIBitset ? , // Necessary ugliness...
344344 at currentPosition: Index ,
345345 limitedBy end: Index
346346 ) -> ( Index , savePointRange: Range < Index > ? ) ? {
347- assert ( payload. quantKind == . eager
348- && payload. minTrips == 1
349- && payload. maxExtraTrips == nil )
347+ assert ( payload. minTrips == 1 && payload. maxExtraTrips == nil )
350348
351- return _runEagerNOrMoreQuantify (
349+ return _runNOrMoreQuantify (
352350 payload,
353351 minTrips: 1 ,
354352 maxTrips: UInt64 . max,
@@ -363,18 +361,21 @@ extension String {
363361 asciiBitset: ASCIIBitset ? , // Necessary ugliness...
364362 at currentPosition: Index ,
365363 limitedBy end: Index
366- ) -> ( Index , makeSavePoint : Bool ) {
367- assert ( payload. minTrips == 0
368- && payload . maxExtraTrips == 1 )
369- guard let next = doQuantifyMatch (
364+ ) -> ( Index , savePointRange : Range < Index > ? ) {
365+ assert ( payload. minTrips == 0 && payload . maxExtraTrips == 1 )
366+
367+ guard let res = _runNOrMoreQuantify (
370368 payload,
369+ minTrips: 0 ,
370+ maxTrips: 1 ,
371371 asciiBitset: asciiBitset,
372372 at: currentPosition,
373373 limitedBy: end
374374 ) else {
375- return ( currentPosition , false )
375+ fatalError ( " Unreachable: zero-or-more always succeeds " )
376376 }
377- return ( next, payload. quantKind != . possessive)
377+
378+ return res
378379 }
379380}
380381
0 commit comments