diff options
author | edef <edef@unfathomable.blue> | 2022-05-02 15:10:17 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-05-02 19:15:42 +0000 |
commit | 832099e432fd3d702681b3c1d852ae99b3bb7d2e (patch) | |
tree | 56c5f09a0f46c4660c77fff29779eee19ae1f65d /ripple | |
parent | 988bb3edce739650088cfc965204280b5ee889a7 (diff) | |
download | unf-legacy-832099e432fd3d702681b3c1d852ae99b3bb7d2e.tar.zst |
ripple/fossil/chunker: use const computation for DISCRIMINATOR
While `const fn` isn't permitted float computation, regular `const` is. This deals with LLVM's reluctance to inline discriminator_from_average, without forcing us to hardcode a magic number. Change-Id: Ibdbfa4c733468517a2feff1ec0deedd1d9b70d47
Diffstat (limited to 'ripple')
-rw-r--r-- | ripple/fossil/src/chunker/mod.rs | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs index 88414a2..59b3367 100644 --- a/ripple/fossil/src/chunker/mod.rs +++ b/ripple/fossil/src/chunker/mod.rs @@ -5,17 +5,15 @@ use std::mem; mod buz; -const WINDOW_SIZE: usize = 48; pub const MIN_CHUNK_SIZE: usize = AVG_CHUNK_SIZE / 4; pub const AVG_CHUNK_SIZE: usize = 64 * 1024; pub const MAX_CHUNK_SIZE: usize = AVG_CHUNK_SIZE * 4; -const DISCRIMINATOR: u32 = 0xc17f; -#[cfg(test)] -fn discriminator_from_average(avg: u64) -> u32 { - let avg = avg as f64; +const WINDOW_SIZE: usize = 48; +const DISCRIMINATOR: u32 = { + let avg = AVG_CHUNK_SIZE as f64; (avg / (-1.42888852e-7 * avg + 1.33237515)) as u32 -} +}; pub struct Chunker<'a> { buffer: &'a [u8], @@ -88,10 +86,7 @@ impl<'a> Iterator for Chunker<'a> { #[cfg(test)] mod test { use { - super::{ - discriminator_from_average, Chunker, AVG_CHUNK_SIZE, DISCRIMINATOR, MAX_CHUNK_SIZE, - MIN_CHUNK_SIZE, WINDOW_SIZE, - }, + super::{Chunker, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, WINDOW_SIZE}, std::io::Read, }; @@ -239,12 +234,4 @@ mod test { (2, Some(MAX_CHUNK_SIZE / MIN_CHUNK_SIZE + 1)) ); } - - #[test] - fn discriminator() { - assert_eq!( - DISCRIMINATOR, - discriminator_from_average(AVG_CHUNK_SIZE as u64) - ); - } } |