Skip to content

Commit 905f4b8

Browse files
committed
perf: guard load_alias on hot path
1 parent 31ff044 commit 905f4b8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,14 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
671671
}
672672
}
673673
// enhanced-resolve: try file as alias
674-
let alias_specifier = cached_path.path().to_string_lossy();
675-
if let Some(path) =
676-
self.load_alias(cached_path, &alias_specifier, &self.options.alias, ctx)?
677-
{
678-
return Ok(Some(path));
674+
// Guard this because this is on a hot path, and `.to_string_lossy()` has a cost.
675+
if !self.options.alias.is_empty() {
676+
let alias_specifier = cached_path.path().to_string_lossy();
677+
if let Some(path) =
678+
self.load_alias(cached_path, &alias_specifier, &self.options.alias, ctx)?
679+
{
680+
return Ok(Some(path));
681+
}
679682
}
680683
if cached_path.is_file(&self.cache.fs, ctx) {
681684
return Ok(Some(cached_path.clone()));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy