add safety comment

This commit is contained in:
fakeshadow 2021-02-10 14:27:47 -08:00
parent 47c6d3b429
commit fcd5775ae6
1 changed files with 6 additions and 0 deletions

View File

@ -19,6 +19,12 @@ fn apply_mask_fallback(buf: &mut [u8], mask: [u8; 4]) {
pub fn apply_mask_fast32(buf: &mut [u8], mask: [u8; 4]) {
let mask_u32 = u32::from_ne_bytes(mask);
// SAFETY:
//
// buf is a valid slice borrowed mutably from bytes::BytesMut.
//
// un aligned prefix and suffix would be mask/unmask per byte.
// proper aligned middle slice goes into fast path and operates on 4-byte blocks.
let (mut prefix, words, mut suffix) = unsafe { buf.align_to_mut::<u32>() };
apply_mask_fallback(&mut prefix, mask);
let head = prefix.len() & 3;