mirror of
https://github.com/mailscope/kumomta.git
synced 2026-10-27 00:36:13 +00:00
replace bytes::find with memchr::memmem::find
This is a much more efficient implementation with ~20% improved
throughput and latency with the simple signing benchmark.
signing/sign time: [1.3024 ms 1.3050 ms 1.3076 ms]
thrpt: [2.2886 MiB/s 2.2933 MiB/s 2.2978 MiB/s]
change:
time: [-19.016% -18.855% -18.691%] (p = 0.00 < 0.05)
thrpt: [+22.987% +23.237% +23.482%]
Performance has improved.
This commit is contained in:
Generated
+1
@@ -131,6 +131,7 @@ dependencies = [
|
||||
"futures",
|
||||
"indexmap",
|
||||
"mailparse",
|
||||
"memchr",
|
||||
"nom",
|
||||
"quick-error 2.0.1",
|
||||
"regex",
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
+1
-7
@@ -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<usize> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user