Skip to content

Commit fc1c36c

Browse files
committed
fix(runtime): use fixed-size chunks in portable binary hashing
1 parent c4e8e1f commit fc1c36c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎crates/nera-runtime/src/phash2.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ fn hc(n: u32) -> u32 {
3636

3737
fn block_hash(bytes: &[u8], initial: u32) -> u32 {
3838
let (mut a, mut b, mut c) = (H, H, initial);
39-
let mut chunks = bytes.chunks_exact(12);
40-
for chunk in &mut chunks {
39+
let (chunks, remainder) = bytes.as_chunks::<12>();
40+
for chunk in chunks {
4141
a = a.wrapping_add(u32::from_le_bytes(chunk[..4].try_into().unwrap()));
4242
b = b.wrapping_add(u32::from_le_bytes(chunk[4..8].try_into().unwrap()));
4343
c = c.wrapping_add(u32::from_le_bytes(chunk[8..].try_into().unwrap()));
4444
// MIX updates all three words; subsequent blocks need a and b too.
4545
mix_words(&mut a, &mut b, &mut c);
4646
}
4747
c = c.wrapping_add(bytes.len() as u32);
48-
for (i, &byte) in chunks.remainder().iter().enumerate() {
48+
for (i, &byte) in remainder.iter().enumerate() {
4949
match i {
5050
0..=3 => a = a.wrapping_add((byte as u32) << (8 * i)),
5151
4..=7 => b = b.wrapping_add((byte as u32) << (8 * (i - 4))),

0 commit comments

Comments
 (0)