Skip to content

Commit

Permalink
refactor: reuse FastInsecureHasher in get_check_hash (denoland#15354
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsherret committed Jul 30, 2022
1 parent 20a89d4 commit ef5653b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cli/cache/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ impl FastInsecureHasher {
self
}

pub fn write_u8(&mut self, value: u8) -> &mut Self {
self.0.write_u8(value);
self
}

pub fn write_u64(&mut self, value: u64) -> &mut Self {
self.0.write_u64(value);
self
Expand Down
10 changes: 3 additions & 7 deletions cli/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,7 @@ fn get_check_hash(
graph_data: &GraphData,
options: &CheckOptions,
) -> CheckHashResult {
// twox hash is insecure, but fast so it works for our purposes
use std::hash::Hasher;
use twox_hash::XxHash64;

let mut hasher = XxHash64::default();
let mut hasher = FastInsecureHasher::new();
hasher.write_u8(match options.type_check_mode {
TypeCheckMode::All => 0,
TypeCheckMode::Local => 1,
Expand Down Expand Up @@ -437,8 +433,8 @@ fn get_check_hash(
| MediaType::Wasm
| MediaType::Unknown => continue,
}
hasher.write(specifier.as_str().as_bytes());
hasher.write(code.as_bytes());
hasher.write_str(specifier.as_str());
hasher.write_str(code);
}
}

Expand Down

0 comments on commit ef5653b

Please sign in to comment.