@@ -432,13 +432,14 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
432
432
#[ inline( always) ]
433
433
fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
434
434
if self . utf8_size == 1 {
435
- return match self
436
- . haystack
437
- . as_bytes ( )
438
- . get ( self . finger ..self . finger_back ) ?
439
- . iter ( )
440
- . position ( |x| * x == self . utf8_encoded [ 0 ] )
441
- {
435
+ let find = |haystack : & [ u8 ] | {
436
+ if haystack. len ( ) < 64 {
437
+ haystack. iter ( ) . position ( |& x| x == self . utf8_encoded [ 0 ] )
438
+ } else {
439
+ memchr:: memchr ( self . utf8_encoded [ 0 ] , haystack)
440
+ }
441
+ } ;
442
+ return match find ( self . haystack . as_bytes ( ) . get ( self . finger ..self . finger_back ) ?) {
442
443
Some ( x) => {
443
444
self . finger += x + 1 ;
444
445
Some ( ( self . finger - 1 , self . finger ) )
@@ -514,13 +515,14 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
514
515
#[ inline]
515
516
fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
516
517
if self . utf8_size == 1 {
517
- return match self
518
- . haystack
519
- . get ( self . finger ..self . finger_back ) ?
520
- . as_bytes ( )
521
- . iter ( )
522
- . rposition ( |& x| x == self . utf8_encoded [ 0 ] )
523
- {
518
+ let find = |haystack : & [ u8 ] | {
519
+ if haystack. len ( ) < 64 {
520
+ memchr:: memrchr ( self . utf8_encoded [ 0 ] , haystack)
521
+ } else {
522
+ haystack. iter ( ) . rposition ( |& x| x == self . utf8_encoded [ 0 ] )
523
+ }
524
+ } ;
525
+ return match find ( self . haystack . as_bytes ( ) . get ( self . finger ..self . finger_back ) ?) {
524
526
Some ( x) => {
525
527
self . finger_back = self . finger + x;
526
528
Some ( ( self . finger_back , self . finger_back + 1 ) )
0 commit comments