diff options
-rw-r--r-- | ripple/fossil/src/chunker/mod.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs index 0e1bdc9..9800e6e 100644 --- a/ripple/fossil/src/chunker/mod.rs +++ b/ripple/fossil/src/chunker/mod.rs @@ -50,8 +50,8 @@ impl<'a> Iterator for Chunker<'a> { Some(bytes) => bytes, }; + // SAFETY: `self.buffer.len() > MIN_CHUNK_SIZE`, so this is in bounds let mut hasher = unsafe { - // SAFETY: `self.buffer.len > MIN_CHUNK_SIZE`, so this is in bounds buz::Rolling::<WINDOW_SIZE>::from_slice_unchecked( self.buffer.get_unchecked(..MIN_CHUNK_SIZE), ) @@ -60,10 +60,9 @@ impl<'a> Iterator for Chunker<'a> { for byte in bytes { let buz::Hash(x) = hasher.sum(); if x % DISCRIMINATOR == DISCRIMINATOR.wrapping_sub(1) { - // split point + // SAFETY: `byte` is in bounds of `self.buffer`, so + // computing `idx` is safe, and `idx` is in bounds return Some(unsafe { - // SAFETY: `byte` is in bounds of `self.buffer`, so - // computing `idx` is safe, and `idx` is in bounds let origin = self.buffer.as_ptr(); let ptr = byte as *const u8; let idx = ptr.offset_from(origin) as usize; @@ -73,10 +72,8 @@ impl<'a> Iterator for Chunker<'a> { hasher.push(*byte); } - Some(unsafe { - // SAFETY: `max_len` is clamped to `self.buffer.len()` - self.cut(max_len) - }) + // SAFETY: `max_len` is clamped to `self.buffer.len()` + Some(unsafe { self.cut(max_len) }) } fn size_hint(&self) -> (usize, Option<usize>) { |