File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -429,8 +429,18 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
429
429
SearchStep :: Done
430
430
}
431
431
}
432
- #[ inline]
432
+ #[ inline( always ) ]
433
433
fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
434
+ if self . utf8_size == 1 {
435
+ let find = |haystack : & [ u8 ] | memchr:: memchr ( self . utf8_encoded [ 0 ] , haystack) ;
436
+ return match find ( self . haystack . as_bytes ( ) . get ( self . finger ..self . finger_back ) ?) {
437
+ Some ( x) => {
438
+ self . finger += x + 1 ;
439
+ Some ( ( self . finger - 1 , self . finger ) )
440
+ }
441
+ None => None ,
442
+ } ;
443
+ }
434
444
loop {
435
445
// get the haystack after the last character found
436
446
let bytes = self . haystack . as_bytes ( ) . get ( self . finger ..self . finger_back ) ?;
@@ -498,6 +508,16 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
498
508
}
499
509
#[ inline]
500
510
fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
511
+ if self . utf8_size == 1 {
512
+ let find = |haystack : & [ u8 ] | memchr:: memrchr ( self . utf8_encoded [ 0 ] , haystack) ;
513
+ return match find ( self . haystack . as_bytes ( ) . get ( self . finger ..self . finger_back ) ?) {
514
+ Some ( x) => {
515
+ self . finger_back = self . finger + x;
516
+ Some ( ( self . finger_back , self . finger_back + 1 ) )
517
+ }
518
+ None => None ,
519
+ } ;
520
+ }
501
521
let haystack = self . haystack . as_bytes ( ) ;
502
522
loop {
503
523
// get the haystack up to but not including the last character searched
You can’t perform that action at this time.
0 commit comments