diff --git a/Cargo.toml b/Cargo.toml index 08852e5a7..6c63775dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ version = "0.2.0" default-features = false [dependencies.memchr] -version = "2.3" +version = "2.4" default-features = false [dev-dependencies] diff --git a/src/traits.rs b/src/traits.rs index 3c3053e89..e903ff0ae 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -922,35 +922,7 @@ pub trait FindSubstring { impl<'a, 'b> FindSubstring<&'b [u8]> for &'a [u8] { fn find_substring(&self, substr: &'b [u8]) -> Option { - if substr.len() > self.len() { - return None; - } - - let (&substr_first, substr_rest) = match substr.split_first() { - Some(split) => split, - // an empty substring is found at position 0 - // This matches the behavior of str.find(""). - None => return Some(0), - }; - - if substr_rest.is_empty() { - return memchr::memchr(substr_first, self); - } - - let mut offset = 0; - let haystack = &self[..self.len() - substr_rest.len()]; - - while let Some(position) = memchr::memchr(substr_first, &haystack[offset..]) { - offset += position; - let next_offset = offset + 1; - if &self[next_offset..][..substr_rest.len()] == substr_rest { - return Some(offset); - } - - offset = next_offset; - } - - None + memchr::memmem::find(&self, substr) } }