summary refs log tree commit diff
path: root/ripple/fossil/src/chunker
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-05-03 01:06:15 +0000
committeredef <edef@unfathomable.blue>2022-05-03 01:06:15 +0000
commit16e9d6fbbc1894b0706378a42123dc01d812e41e (patch)
tree2144e87e47a50c47d109ae5aa814ae62136bfefa /ripple/fossil/src/chunker
parentfb6290d73a5df1ce34c87c07e1e8da23a45641c4 (diff)
downloadunf-legacy-16e9d6fbbc1894b0706378a42123dc01d812e41e.tar.zst
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
Diffstat (limited to 'ripple/fossil/src/chunker')
-rw-r--r--ripple/fossil/src/chunker/mod.rs13
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>) {