Skip to content

Commit 3d33877

Browse files
committed
dont ever position()
1 parent e65ed1f commit 3d33877

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

library/core/src/str/pattern.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,7 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
432432
#[inline(always)]
433433
fn next_match(&mut self) -> Option<(usize, usize)> {
434434
if self.utf8_size == 1 {
435-
let find = |haystack: &[u8]| {
436-
if haystack.len() < 32 {
437-
haystack.iter().position(|&x| x == self.utf8_encoded[0])
438-
} else {
439-
memchr::memchr(self.utf8_encoded[0], haystack)
440-
}
441-
};
435+
let find = |haystack: &[u8]| memchr::memchr(self.utf8_encoded[0], haystack);
442436
return match find(self.haystack.as_bytes().get(self.finger..self.finger_back)?) {
443437
Some(x) => {
444438
self.finger += x + 1;
@@ -515,13 +509,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
515509
#[inline]
516510
fn next_match_back(&mut self) -> Option<(usize, usize)> {
517511
if self.utf8_size == 1 {
518-
let find = |haystack: &[u8]| {
519-
if haystack.len() < 32 {
520-
haystack.iter().rposition(|&x| x == self.utf8_encoded[0])
521-
} else {
522-
memchr::memrchr(self.utf8_encoded[0], haystack)
523-
}
524-
};
512+
let find = |haystack: &[u8]| memchr::memrchr(self.utf8_encoded[0], haystack);
525513
return match find(self.haystack.as_bytes().get(self.finger..self.finger_back)?) {
526514
Some(x) => {
527515
self.finger_back = self.finger + x;

0 commit comments

Comments
 (0)