@@ -27,20 +27,14 @@ impl Matcher for ExactMatcher<'_> {
2727 fn next_match ( & self , haystack : & [ u8 ] ) -> Option < ( usize , usize ) > {
2828 let mut pos = 0usize ;
2929 loop {
30- match memchr ( self . needle [ 0 ] , & haystack[ pos..] ) {
31- Some ( match_idx) => {
32- let match_idx = match_idx + pos; // account for starting from pos
33- if self . needle . len ( ) == 1
34- || haystack[ match_idx + 1 ..] . starts_with ( & self . needle [ 1 ..] )
35- {
36- return Some ( ( match_idx, match_idx + self . needle . len ( ) ) ) ;
37- }
38- pos = match_idx + 1 ;
39- }
40- None => {
41- return None ;
42- }
30+ let match_idx = memchr ( self . needle [ 0 ] , & haystack[ pos..] ) ?;
31+ let match_idx = match_idx + pos; // account for starting from pos
32+
33+ if self . needle . len ( ) == 1 || haystack[ match_idx + 1 ..] . starts_with ( & self . needle [ 1 ..] ) {
34+ return Some ( ( match_idx, match_idx + self . needle . len ( ) ) ) ;
4335 }
36+
37+ pos = match_idx + 1 ;
4438 }
4539 }
4640}
@@ -50,19 +44,17 @@ pub struct WhitespaceMatcher {}
5044
5145impl Matcher for WhitespaceMatcher {
5246 fn next_match ( & self , haystack : & [ u8 ] ) -> Option < ( usize , usize ) > {
53- match memchr2 ( b' ' , b'\t' , haystack) {
54- Some ( match_idx) => {
55- let mut skip = match_idx + 1 ;
56- while skip < haystack. len ( ) {
57- match haystack[ skip] {
58- b' ' | b'\t' => skip += 1 ,
59- _ => break ,
60- }
61- }
62- Some ( ( match_idx, skip) )
47+ let match_idx = memchr2 ( b' ' , b'\t' , haystack) ?;
48+ let mut skip = match_idx + 1 ;
49+
50+ while skip < haystack. len ( ) {
51+ match haystack[ skip] {
52+ b' ' | b'\t' => skip += 1 ,
53+ _ => break ,
6354 }
64- None => None ,
6555 }
56+
57+ Some ( ( match_idx, skip) )
6658 }
6759}
6860
0 commit comments