Skip to content

Commit

Permalink
switch to blake3
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jan 16, 2024
1 parent 26855d6 commit 79476d1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
39 changes: 32 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ahash = "0.8.6"
hashbrown = { version = "0.14.3", features = ["raw"] }
dunce = "1.0"

xxhash-rust = { version = "0.8.8", features = ["xxh3"] }
blake3 = "1.5"
anyhow = "1"

log = "0.4"
Expand All @@ -58,5 +58,5 @@ parking_lot = "0.12"
[dev-dependencies]
quickcheck = { version = "1", default-features = false }
indoc = "2.0.4"
rand = { version = "0.8", default-features = false, features = ["getrandom", "small_rng"] }
tempfile = "3.9"
rand = { version = "0.8", default-features = false, features = ["getrandom", "small_rng"] }
19 changes: 4 additions & 15 deletions helix-core/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,11 @@ impl Default for History {
}
}

const HASH_DIGEST_LENGTH: usize = std::mem::size_of::<u128>();
const HASH_DIGEST_LENGTH: usize = blake3::OUT_LEN;
fn get_hash<R: Read>(reader: &mut R) -> std::io::Result<[u8; HASH_DIGEST_LENGTH]> {
const BUF_SIZE: usize = 8192;

let mut buf = [0u8; BUF_SIZE];
let mut hash = Box::new(xxhash_rust::xxh3::Xxh3::new());
loop {
let total_read = reader.read(&mut buf)?;
if total_read == 0 {
break;
}

hash.update(&buf[0..total_read]);
}
let bytes = hash.digest128().to_ne_bytes();
Ok(bytes)
let mut hasher = blake3::Hasher::new();
hasher.update_reader(reader)?;
Ok(hasher.finalize().as_bytes().to_owned())
}

#[derive(Debug)]
Expand Down

0 comments on commit 79476d1

Please sign in to comment.