From 16e9d6fbbc1894b0706378a42123dc01d812e41e Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 3 May 2022 01:06:15 +0000 Subject: ripple/fossil/chunker: clean up SAFETY comments stdlib code seems to place these before the blocks, so let's copy their style. Change-Id: Ic77ed43bc8c6807c5ddb126e624f263f8bca5b66 --- ripple/fossil/src/chunker/mod.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'ripple/fossil') 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::::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) { -- cgit 1.4.1