Skip to content

Commit

Permalink
perf: guard load_alias on hot path (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Dec 11, 2024
1 parent 31ff044 commit cc3b760
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,14 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
}
}
// enhanced-resolve: try file as alias
let alias_specifier = cached_path.path().to_string_lossy();
if let Some(path) =
self.load_alias(cached_path, &alias_specifier, &self.options.alias, ctx)?
{
return Ok(Some(path));
// Guard this because this is on a hot path, and `.to_string_lossy()` has a cost.
if !self.options.alias.is_empty() {
let alias_specifier = cached_path.path().to_string_lossy();
if let Some(path) =
self.load_alias(cached_path, &alias_specifier, &self.options.alias, ctx)?
{
return Ok(Some(path));
}
}
if cached_path.is_file(&self.cache.fs, ctx) {
return Ok(Some(cached_path.clone()));
Expand Down

0 comments on commit cc3b760

Please sign in to comment.