Speed up apply_mask()

This function is the most speed-critical in the library. In profiles,
this optimization reduces it from ~75% of the profile to ~55%.

I have tried several approaches, but didn't manage to improve on this
one (LLVM already unrolls the loop here). Though I'm sure it is possible.
pull/7/head
Ran Benita 8 years ago
parent ea4b5e4df0
commit dd96d3b9d4
  1. 5
      src/protocol/frame/frame.rs

@ -14,9 +14,8 @@ use error::{Error, Result};
use super::coding::{OpCode, Control, Data, CloseCode};
fn apply_mask(buf: &mut [u8], mask: &[u8; 4]) {
let iter = buf.iter_mut().zip(mask.iter().cycle());
for (byte, &key) in iter {
*byte ^= key
for (i, byte) in buf.iter_mut().enumerate() {
*byte ^= mask[i & 3];
}
}

Loading…
Cancel
Save