diff --git a/Cargo.lock b/Cargo.lock index 7227bb12..6c757e08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,7 @@ dependencies = [ "futures", "indexmap", "mailparse", + "memchr", "nom", "quick-error 2.0.1", "regex", diff --git a/Cargo.toml b/Cargo.toml index c3d7fb86..83d913a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ license = "MIT" [dependencies] ed25519-dalek = "1.0.1" mailparse = "0.14" +memchr = "2.5" quick-error = "2.0.1" nom = "7.1.0" chrono = { version = "0.4.19", default-features = false, features = ["clock", "std"] } diff --git a/src/bytes.rs b/src/bytes.rs index ec82e3a7..b00a65a5 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1,4 +1,5 @@ ///! Various utility functions to operate on bytes +pub(crate) use memchr::memmem::find; pub(crate) fn get_all_after<'a>(bytes: &'a [u8], end: &[u8]) -> &'a [u8] { if let Some(mut end_index) = find(bytes, end) { @@ -9,13 +10,6 @@ pub(crate) fn get_all_after<'a>(bytes: &'a [u8], end: &[u8]) -> &'a [u8] { } } -/// Find the offset of specific bytes in bytes -pub(crate) fn find(bytes: &[u8], search: &[u8]) -> Option { - bytes - .windows(search.len()) - .position(|window| window == search) -} - pub(crate) fn replace(bytes: &mut [u8], from: char, to: char) { for byte in bytes.iter_mut() { if *byte == from as u8 {