diff --git a/Cargo.lock b/Cargo.lock index d88a9dd34f6b7..39e07e05f1169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,18 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "autocfg" version = "1.1.0" @@ -105,6 +117,19 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +[[package]] +name = "blake3" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "bstr" version = "1.8.0" @@ -206,6 +231,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "content_inspector" version = "0.2.4" @@ -1055,6 +1086,7 @@ dependencies = [ "anyhow", "arc-swap", "bitflags 2.4.1", + "blake3", "chrono", "dunce", "encoding_rs", @@ -1083,7 +1115,6 @@ dependencies = [ "unicode-general-category", "unicode-segmentation", "unicode-width", - "xxhash-rust", ] [[package]] @@ -2636,12 +2667,6 @@ dependencies = [ "toml", ] -[[package]] -name = "xxhash-rust" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53be06678ed9e83edb1745eb72efc0bbcd7b5c3c35711a860906aed827a13d61" - [[package]] name = "zerocopy" version = "0.7.31" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 0215bb41d8138..0422851730426 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -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" diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 6705cc6dd69ec..d2fa6000c590a 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -86,22 +86,11 @@ impl Default for History { } } -const HASH_DIGEST_LENGTH: usize = std::mem::size_of::(); +const HASH_DIGEST_LENGTH: usize = blake3::OUT_LEN; fn get_hash(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)]