From a2e122ab9e315da24a1d49d3988d12ec84503d85 Mon Sep 17 00:00:00 2001 From: Alexey Galakhov Date: Wed, 11 Jul 2018 19:04:02 +0200 Subject: [PATCH] refactor: mask: pass mask by value Signed-off-by: Alexey Galakhov --- src/protocol/frame/frame.rs | 2 +- src/protocol/frame/mask.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/protocol/frame/frame.rs b/src/protocol/frame/frame.rs index fba686a..c5bf9c2 100644 --- a/src/protocol/frame/frame.rs +++ b/src/protocol/frame/frame.rs @@ -269,7 +269,7 @@ impl Frame { #[inline] pub(crate) fn apply_mask(&mut self) { if let Some(mask) = self.header.mask.take() { - apply_mask(&mut self.payload, &mask) + apply_mask(&mut self.payload, mask) } } diff --git a/src/protocol/frame/mask.rs b/src/protocol/frame/mask.rs index 055be08..8b39d76 100644 --- a/src/protocol/frame/mask.rs +++ b/src/protocol/frame/mask.rs @@ -11,14 +11,14 @@ pub fn generate_mask() -> [u8; 4] { /// Mask/unmask a frame. #[inline] -pub fn apply_mask(buf: &mut [u8], mask: &[u8; 4]) { +pub fn apply_mask(buf: &mut [u8], mask: [u8; 4]) { apply_mask_fast32(buf, mask) } /// A safe unoptimized mask application. #[inline] #[allow(dead_code)] -fn apply_mask_fallback(buf: &mut [u8], mask: &[u8; 4]) { +fn apply_mask_fallback(buf: &mut [u8], mask: [u8; 4]) { for (i, byte) in buf.iter_mut().enumerate() { *byte ^= mask[i & 3]; } @@ -27,7 +27,7 @@ fn apply_mask_fallback(buf: &mut [u8], mask: &[u8; 4]) { /// Faster version of `apply_mask()` which operates on 4-byte blocks. #[inline] #[allow(dead_code)] -fn apply_mask_fast32(buf: &mut [u8], mask: &[u8; 4]) { +fn apply_mask_fast32(buf: &mut [u8], mask: [u8; 4]) { let mask_u32: u32 = unsafe { read_unaligned(mask.as_ptr() as *const u32) }; @@ -101,10 +101,10 @@ mod tests { // Check masking with proper alignment. { let mut masked = unmasked.clone(); - apply_mask_fallback(&mut masked, &mask); + apply_mask_fallback(&mut masked, mask); let mut masked_fast = unmasked.clone(); - apply_mask_fast32(&mut masked_fast, &mask); + apply_mask_fast32(&mut masked_fast, mask); assert_eq!(masked, masked_fast); } @@ -112,10 +112,10 @@ mod tests { // Check masking without alignment. { let mut masked = unmasked.clone(); - apply_mask_fallback(&mut masked[1..], &mask); + apply_mask_fallback(&mut masked[1..], mask); let mut masked_fast = unmasked.clone(); - apply_mask_fast32(&mut masked_fast[1..], &mask); + apply_mask_fast32(&mut masked_fast[1..], mask); assert_eq!(masked, masked_fast); }