diff --git a/Cargo.lock b/Cargo.lock index 8dadfefe4..acad012eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -931,12 +931,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "identity-hash" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfdd7caa900436d8f13b2346fe10257e0c05c1f1f9e351f4f5d57c03bd5f45da" - [[package]] name = "idna" version = "0.4.0" @@ -1751,7 +1745,6 @@ dependencies = [ "criterion", "dashmap", "dunce", - "identity-hash", "indexmap 2.0.0", "jemallocator", "mimalloc", diff --git a/crates/oxc_resolver/Cargo.toml b/crates/oxc_resolver/Cargo.toml index 2ddf27b29..505741963 100644 --- a/crates/oxc_resolver/Cargo.toml +++ b/crates/oxc_resolver/Cargo.toml @@ -19,7 +19,6 @@ serde_json = { workspace = true } rustc-hash = { workspace = true } indexmap = { workspace = true, features = ["serde"] } dunce = "1.0.4" -identity-hash = "0.1.0" # Use `std::sync::OnceLock::get_or_try_init` when it is stable. once_cell = "1.18.0" diff --git a/crates/oxc_resolver/src/cache.rs b/crates/oxc_resolver/src/cache.rs index 7a910789f..519a24cd6 100644 --- a/crates/oxc_resolver/src/cache.rs +++ b/crates/oxc_resolver/src/cache.rs @@ -1,14 +1,13 @@ use once_cell::sync::OnceCell as OnceLock; use std::{ convert::AsRef, - hash::{Hash, Hasher}, + hash::{BuildHasherDefault, Hash, Hasher}, ops::Deref, path::{Path, PathBuf}, sync::Arc, }; use dashmap::DashMap; -use identity_hash::BuildIdentityHasher; use rustc_hash::FxHasher; use crate::{package_json::PackageJson, FileMetadata, FileSystem, ResolveError}; @@ -16,7 +15,22 @@ use crate::{package_json::PackageJson, FileMetadata, FileSystem, ResolveError}; pub struct Cache { pub(crate) fs: Fs, // Using IdentityHasher to avoid double hashing in the `get` + `insert` case. - cache: DashMap>, + cache: DashMap>, +} + +#[derive(Default)] +struct IdentityHasher(u64); + +impl Hasher for IdentityHasher { + fn write(&mut self, _: &[u8]) { + panic!("Invalid use of IdentityHasher") + } + fn write_u64(&mut self, n: u64) { + self.0 = n; + } + fn finish(&self) -> u64 { + self.0 + } } impl Default for Cache {