1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

refactor: reuse FastInsecureHasher in get_check_hash (#15354)

This commit is contained in:
David Sherret 2022-07-30 11:43:03 -04:00 committed by GitHub
parent 20a89d46c4
commit ef5653be98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

5
cli/cache/common.rs vendored
View file

@ -24,6 +24,11 @@ impl FastInsecureHasher {
self 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 { pub fn write_u64(&mut self, value: u64) -> &mut Self {
self.0.write_u64(value); self.0.write_u64(value);
self self

View file

@ -382,11 +382,7 @@ fn get_check_hash(
graph_data: &GraphData, graph_data: &GraphData,
options: &CheckOptions, options: &CheckOptions,
) -> CheckHashResult { ) -> CheckHashResult {
// twox hash is insecure, but fast so it works for our purposes let mut hasher = FastInsecureHasher::new();
use std::hash::Hasher;
use twox_hash::XxHash64;
let mut hasher = XxHash64::default();
hasher.write_u8(match options.type_check_mode { hasher.write_u8(match options.type_check_mode {
TypeCheckMode::All => 0, TypeCheckMode::All => 0,
TypeCheckMode::Local => 1, TypeCheckMode::Local => 1,
@ -437,8 +433,8 @@ fn get_check_hash(
| MediaType::Wasm | MediaType::Wasm
| MediaType::Unknown => continue, | MediaType::Unknown => continue,
} }
hasher.write(specifier.as_str().as_bytes()); hasher.write_str(specifier.as_str());
hasher.write(code.as_bytes()); hasher.write_str(code);
} }
} }