From 78c65f51b4ffc1e1fa21a373013b05e6d356ed51 Mon Sep 17 00:00:00 2001 From: Nick Babcock Date: Sat, 11 Nov 2023 13:15:53 -0600 Subject: [PATCH] Optimize `get_split` utility Throughput of ondemand binary deserializer improves 0-6%. Looked into it a bit and I'm not sure where the throughput improvement comes from as this method generates more assembly. --- src/util.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/util.rs b/src/util.rs index 5793f1b..5afd1c3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,12 +7,7 @@ fn take(data: &[u8]) -> [u8; N] { #[inline] pub(crate) fn get_split(data: &[u8]) -> Option<([u8; N], &[u8])> { - if N <= data.len() { - let (head, tail) = data.split_at(N); - Some((take::(head), tail)) - } else { - None - } + data.get(N..).map(|d| (take::(data), d)) } #[inline]