@@ -243,6 +243,7 @@ extension Processor {
243
243
}
244
244
245
245
mutating func matchCaseInsensitive( _ e: Element ) -> Bool {
246
+ // TODO: need benchmark coverage
246
247
guard let cur = load ( ) , cur. lowercased ( ) == e. lowercased ( ) else {
247
248
signalFailure ( )
248
249
return false
@@ -290,6 +291,7 @@ extension Processor {
290
291
_ s: Unicode . Scalar ,
291
292
boundaryCheck: Bool
292
293
) -> Bool {
294
+ // TODO: needs benchmark coverage
293
295
guard let curScalar = loadScalar ( ) ,
294
296
s. properties. lowercaseMapping == curScalar. properties. lowercaseMapping,
295
297
let idx = input. unicodeScalars. index (
@@ -305,21 +307,15 @@ extension Processor {
305
307
return true
306
308
}
307
309
308
- func _doMatchBitset( _ bitset: DSLTree . CustomCharacterClass . AsciiBitset ) -> Input . Index ? {
309
- if let cur = load ( ) , bitset. matches ( char: cur) {
310
- return input. index ( after: currentPosition)
311
- } else {
312
- return nil
313
- }
314
- }
315
-
316
310
// If we have a bitset we know that the CharacterClass only matches against
317
311
// ascii characters, so check if the current input element is ascii then
318
312
// check if it is set in the bitset
319
313
mutating func matchBitset(
320
314
_ bitset: DSLTree . CustomCharacterClass . AsciiBitset
321
315
) -> Bool {
322
- guard let next = _doMatchBitset ( bitset) else {
316
+ guard let next = input. matchBitset (
317
+ bitset, at: currentPosition, limitedBy: end
318
+ ) else {
323
319
signalFailure ( )
324
320
return false
325
321
}
@@ -748,4 +744,25 @@ extension String {
748
744
return idx
749
745
}
750
746
747
+ func matchBitset(
748
+ _ bitset: DSLTree . CustomCharacterClass . AsciiBitset ,
749
+ at pos: Index ,
750
+ limitedBy end: Index
751
+ ) -> Index ? {
752
+ // TODO: extremely quick-check-able
753
+ // TODO: can be sped up with string internals
754
+
755
+ assert ( end <= endIndex)
756
+
757
+ guard pos < end, bitset. matches ( char: self [ pos] ) else {
758
+ return nil
759
+ }
760
+
761
+ let idx = index ( after: pos)
762
+ guard idx <= end else { return nil }
763
+
764
+ return idx
765
+ }
766
+
767
+
751
768
}
0 commit comments