mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(resolver): remove the identity-hash crate
This commit is contained in:
parent
341c678b2f
commit
fdded5e97c
3 changed files with 17 additions and 11 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Fs> {
|
||||
pub(crate) fs: Fs,
|
||||
// Using IdentityHasher to avoid double hashing in the `get` + `insert` case.
|
||||
cache: DashMap<u64, CachedPath, BuildIdentityHasher<u64>>,
|
||||
cache: DashMap<u64, CachedPath, BuildHasherDefault<IdentityHasher>>,
|
||||
}
|
||||
|
||||
#[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<Fs: FileSystem> Default for Cache<Fs> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue