@@ -58,31 +58,36 @@ extension Processor {
58
58
trips += 1
59
59
}
60
60
61
- var savePoint = startQuantifierSavePoint (
62
- isScalarSemantics: payload. isScalarSemantics
63
- )
61
+ if maxExtraTrips == 0 {
62
+ // We're done
63
+ return true
64
+ }
65
+
66
+ guard let next = _doQuantifyMatch ( payload) else {
67
+ return true
68
+ }
69
+ maxExtraTrips = maxExtraTrips. map { $0 - 1 }
70
+
71
+ // Remember the range of valid positions in case we can create a quantified
72
+ // save point
73
+ let rangeStart = currentPosition
74
+ var rangeEnd = currentPosition
75
+ currentPosition = next
76
+
64
77
while true {
65
78
if maxExtraTrips == 0 { break }
66
- maxExtraTrips = maxExtraTrips. map ( { $0 - 1 } )
67
- if payload. quantKind == . eager {
68
- savePoint. updateRange ( newEnd: currentPosition)
69
- }
70
79
71
- let next = _doQuantifyMatch ( payload)
72
- guard let idx = next else {
73
- if savePoint. isQuantified {
74
- // The last save point has saved the current, non-matching position,
75
- // so it's unneeded.
76
- savePoint. shrinkRange ( input)
77
- }
80
+ guard let next = _doQuantifyMatch ( payload) else {
78
81
break
79
82
}
80
- currentPosition = idx
81
- trips += 1
83
+ maxExtraTrips = maxExtraTrips. map ( { $0 - 1 } )
84
+ rangeEnd = currentPosition
85
+ currentPosition = next
82
86
}
83
87
84
- if savePoint. isQuantified {
85
- savePoints. append ( savePoint)
88
+ if payload. quantKind == . eager {
89
+ savePoints. append ( makeQuantifiedSavePoint (
90
+ rangeStart..< rangeEnd, isScalarSemantics: payload. isScalarSemantics) )
86
91
}
87
92
return true
88
93
}
@@ -108,6 +113,7 @@ extension Processor {
108
113
// to the final position.
109
114
let rangeStart = currentPosition
110
115
var rangeEnd = currentPosition
116
+ currentPosition = next
111
117
while true {
112
118
guard let next = _doQuantifyMatch ( payload) else { break }
113
119
rangeEnd = currentPosition
0 commit comments