From f790f49b5d5732295c113d46fe9c0a1ec042992f Mon Sep 17 00:00:00 2001 From: Luca BRUNO Date: Wed, 19 Jun 2024 19:34:52 +0200 Subject: [PATCH] perf: use plain iterator for payload unmasking This tweaks `unmask_easy` logic in order to directly use an enumerating iterator. It allows the compiler to generate more optimal machine code by performing internal iteration directly on the input slice. --- src/mask.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mask.rs b/src/mask.rs index c28cb24..ba51f38 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -14,9 +14,9 @@ #[inline] fn unmask_easy(payload: &mut [u8], mask: [u8; 4]) { - for i in 0..payload.len() { - payload[i] ^= mask[i & 3]; - } + payload.iter_mut().enumerate().for_each(|(i, v)| { + *v ^= mask[i & 3]; + }); } // TODO(@littledivy): Compiler does a good job at auto-vectorizing `unmask_fallback` with