summary refs log tree commit diff
path: root/ripple/fossil/src
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r--ripple/fossil/src/chunker/buz.rs9
-rw-r--r--ripple/fossil/src/chunker/mod.rs7
2 files changed, 10 insertions, 6 deletions
diff --git a/ripple/fossil/src/chunker/buz.rs b/ripple/fossil/src/chunker/buz.rs
index cd12833..6ddb08b 100644
--- a/ripple/fossil/src/chunker/buz.rs
+++ b/ripple/fossil/src/chunker/buz.rs
@@ -24,11 +24,10 @@ pub struct Rolling<const N: usize> {
 }
 
 impl<const N: usize> Rolling<N> {
-	pub fn from_slice(input: &[u8]) -> Rolling<N> {
-		let last_chunk = input
-			.rchunks_exact(N)
-			.next()
-			.expect("need at least Rolling::WINDOW_SIZE bytes");
+	/// SAFETY: `input.len() >= N` must hold
+	#[inline]
+	pub unsafe fn from_slice_unchecked(input: &[u8]) -> Rolling<N> {
+		let last_chunk = input.rchunks_exact(N).next().unwrap_unchecked();
 
 		let mut window = [0; N];
 		window.copy_from_slice(last_chunk);
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs
index 16e81a2..88414a2 100644
--- a/ripple/fossil/src/chunker/mod.rs
+++ b/ripple/fossil/src/chunker/mod.rs
@@ -49,7 +49,12 @@ impl<'a> Iterator for Chunker<'a> {
 		}
 
 		let bytes = self.buffer.iter().take(MAX_CHUNK_SIZE).skip(MIN_CHUNK_SIZE);
-		let mut hasher = buz::Rolling::<WINDOW_SIZE>::from_slice(&self.buffer[..MIN_CHUNK_SIZE]);
+		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),
+			)
+		};
 		for byte in bytes {
 			let buz::Hash(x) = hasher.sum();
 			if x % DISCRIMINATOR == DISCRIMINATOR.wrapping_sub(1) {