Skip to content

Commit

Permalink
replacing ahash with blake3
Browse files Browse the repository at this point in the history
  • Loading branch information
TornaxO7 committed May 2, 2024
1 parent 2499e50 commit 75b87d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
35 changes: 34 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ toml = "0.8"
log = "~0.4"

parking_lot = "0.12.1"
ahash = "0.8.11"

blake3 = { version = "1.5.1", features = ["mmap", "rayon"] }

[target.'cfg(windows)'.dependencies]
clipboard-win = { version = "5.3", features = ["std"] }
Expand Down
19 changes: 8 additions & 11 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ahash::AHasher;
use anyhow::{anyhow, bail, Context, Error};
use arc_swap::access::DynAccess;
use arc_swap::ArcSwap;
Expand All @@ -22,7 +21,6 @@ use std::cell::Cell;
use std::collections::HashMap;
use std::fmt::Display;
use std::future::Future;
use std::hash::Hasher;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::{Arc, Weak};
Expand Down Expand Up @@ -890,17 +888,16 @@ impl Document {
if let Ok(metadata) = fs::metadata(&path).await {
if let Ok(mtime) = metadata.modified() {
if last_saved_time < mtime {
let external_content = fs::read(&path).await?;
let mut external_hasher = blake3::Hasher::default();
let mut editor_hasher = blake3::Hasher::default();

let mut external_hasher = AHasher::default();
let mut editor_hasher = AHasher::default();
external_hasher.update_mmap_rayon(&path)?;
text.chunks().for_each(|chunk| {
editor_hasher.update(chunk.as_bytes());
});

external_hasher.write(&external_content);
text.chunks()
.for_each(|chunk| editor_hasher.write(chunk.as_bytes()));

let external_change_hash = external_hasher.finish();
let editor_hash = editor_hasher.finish();
let external_change_hash = external_hasher.finalize();
let editor_hash = editor_hasher.finalize();

if external_change_hash != editor_hash {
bail!("file modified by an external process, use :w! to overwrite");
Expand Down

0 comments on commit 75b87d8

Please sign in to comment.