summary refs log tree commit diff
path: root/ripple/fossil/src/chunker/mod.rs
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-05-02 18:37:30 +0000
committeredef <edef@unfathomable.blue>2022-05-02 18:37:30 +0000
commit988bb3edce739650088cfc965204280b5ee889a7 (patch)
tree10317b597535695a93f7cede3396223ca672de4a /ripple/fossil/src/chunker/mod.rs
parent71c71783d4efa7f44af910daf015e6972f069472 (diff)
downloadunf-legacy-988bb3edce739650088cfc965204280b5ee889a7.tar.zst
ripple/fossil/chunker: remove hasher initialisation bounds check
We already check for `self.buffer.len() <= MIN_CHUNK_SIZE`, but LLVM
doesn't seem to notice. This boosts throughput by 35%.

Change-Id: I1a0e07d276dcc285f8dec3149a629cb6e865c286
Diffstat (limited to 'ripple/fossil/src/chunker/mod.rs')
-rw-r--r--ripple/fossil/src/chunker/mod.rs7
1 files changed, 6 insertions, 1 deletions
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) {