diff --git a/Cargo.lock b/Cargo.lock index 56e61c8311e67..d88a9dd34f6b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,7 +1073,6 @@ dependencies = [ "ropey", "serde", "serde_json", - "sha1_smol", "slotmap", "smallvec", "smartstring", @@ -1084,6 +1083,7 @@ dependencies = [ "unicode-general-category", "unicode-segmentation", "unicode-width", + "xxhash-rust", ] [[package]] @@ -2636,6 +2636,12 @@ 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 3028df5e40c18..0215bb41d8138 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" -sha1_smol = "1.0" +xxhash-rust = { version = "0.8.8", features = ["xxh3"] } anyhow = "1" log = "0.4" diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 25f95cf13b4b4..6705cc6dd69ec 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -86,11 +86,12 @@ impl Default for History { } } -fn get_hash(reader: &mut R) -> std::io::Result<[u8; sha1_smol::DIGEST_LENGTH]> { +const HASH_DIGEST_LENGTH: usize = std::mem::size_of::(); +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 = sha1_smol::Sha1::new(); + let mut hash = Box::new(xxhash_rust::xxh3::Xxh3::new()); loop { let total_read = reader.read(&mut buf)?; if total_read == 0 { @@ -99,7 +100,8 @@ fn get_hash(reader: &mut R) -> std::io::Result<[u8; sha1_smol::DIGEST_L hash.update(&buf[0..total_read]); } - Ok(hash.digest().bytes()) + let bytes = hash.digest128().to_ne_bytes(); + Ok(bytes) } #[derive(Debug)] @@ -200,16 +202,10 @@ impl History { last_saved_revision: usize, ) -> Result<(), StateError> { // Header - let mtime = std::fs::metadata(path)? - .modified()? - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_secs(); writer.write_all(UNDO_FILE_HEADER_TAG)?; write_byte(writer, UNDO_FILE_VERSION)?; write_usize(writer, self.current)?; write_usize(writer, revision)?; - write_u64(writer, mtime)?; writer.write_all(&get_hash(&mut std::fs::File::open(path)?)?)?; // Append new revisions to the end of the file. @@ -316,16 +312,10 @@ impl History { } else { let current = read_usize(reader)?; let last_saved_revision = read_usize(reader)?; - let mtime = read_u64(reader)?; - let last_mtime = std::fs::metadata(path)? - .modified()? - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_secs(); - let mut hash = [0u8; sha1_smol::DIGEST_LENGTH]; + let mut hash = [0u8; HASH_DIGEST_LENGTH]; reader.read_exact(&mut hash)?; - if mtime != last_mtime && hash != get_hash(&mut std::fs::File::open(path)?)? { + if hash != get_hash(&mut std::fs::File::open(path)?)? { anyhow::bail!(StateError::Outdated); }