@@ -232,11 +232,13 @@ extension Processor {
232
232
// Match against the current input element. Returns whether
233
233
// it succeeded vs signaling an error.
234
234
mutating func match( _ e: Element ) -> Bool {
235
- guard let cur = load ( ) , cur == e else {
235
+ guard let next = input. match (
236
+ e, at: currentPosition, limitedBy: end
237
+ ) else {
236
238
signalFailure ( )
237
239
return false
238
240
}
239
- _uncheckedForcedConsumeOne ( )
241
+ currentPosition = next
240
242
return true
241
243
}
242
244
@@ -256,6 +258,7 @@ extension Processor {
256
258
isScalarMode: Bool
257
259
) -> Bool {
258
260
if isScalarMode {
261
+ // TODO: sink to specialized method on string, needs benchmark
259
262
for s in seq. unicodeScalars {
260
263
guard matchScalar ( s, boundaryCheck: false ) else { return false }
261
264
}
@@ -702,6 +705,23 @@ func blackHole<T>(_ t: T) { _ = t }
702
705
703
706
extension String {
704
707
708
+ func match(
709
+ _ char: Character ,
710
+ at pos: Index ,
711
+ limitedBy end: String . Index
712
+ ) -> Index ? {
713
+ // TODO: This can be greatly sped up with string internals
714
+ // TODO: This is also very much quick-check-able
715
+ assert ( end <= endIndex)
716
+
717
+ guard pos < end, self [ pos] == char else { return nil }
718
+
719
+ let idx = index ( after: pos)
720
+ guard idx <= end else { return nil }
721
+
722
+ return idx
723
+ }
724
+
705
725
// func consumeScalar(_ n: Distance) -> Bool {
706
726
707
727
// }
0 commit comments