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