Skip to content

Commit

Permalink
perf(linter): use OsString for module cache hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 1, 2024
1 parent 8392177 commit e699619
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crates/oxc_linter/src/service/module_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
ffi::OsString,
num::NonZeroUsize,
path::Path,
sync::{Arc, Condvar, Mutex},
Expand Down Expand Up @@ -29,7 +30,8 @@ enum CacheStateEntry {
}

/// Keyed by canonicalized path
type ModuleMap = FxDashMap<Box<Path>, ModuleState>;
/// `OsString` hash is after than `Path` - go checkout their source code.
type ModuleMap = FxDashMap<OsString, ModuleState>;

#[derive(Clone)]
pub(super) enum ModuleState {
Expand All @@ -45,8 +47,8 @@ pub(super) struct ModuleCache {

impl ModuleCache {
#[inline]
pub fn get(&self, path: &Path) -> Option<Ref<'_, Box<Path>, ModuleState>> {
self.modules.get(path)
pub fn get(&self, path: &Path) -> Option<Ref<'_, OsString, ModuleState>> {
self.modules.get(path.as_os_str())
}

#[inline]
Expand All @@ -67,7 +69,7 @@ impl ModuleCache {
})
.unwrap();

let cache_hit = if self.modules.contains_key(path) {
let cache_hit = if self.modules.contains_key(path.as_os_str()) {
true
} else {
let i = if let CacheStateEntry::PendingStore(i) = *state { i.get() } else { 0 };
Expand All @@ -87,16 +89,14 @@ impl ModuleCache {
/// # Panics
/// If a cache entry for `path` does not exist. You must call `init_cache_state` first.
pub(super) fn add_resolved_module(&self, path: &Path, module_record: Arc<ModuleRecord>) {
self.modules
.insert(path.to_path_buf().into_boxed_path(), ModuleState::Resolved(module_record));

self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Resolved(module_record));
self.update_cache_state(path);
}

/// # Panics
/// If a cache entry for `path` does not exist. You must call `init_cache_state` first.
pub(super) fn ignore_path(&self, path: &Path) {
self.modules.insert(path.to_path_buf().into_boxed_path(), ModuleState::Ignored);
self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Ignored);
self.update_cache_state(path);
}

Expand Down

0 comments on commit e699619

Please sign in to comment.