Skip to content

Commit f917412

Browse files
authored
perf: remove an allocation from CachedPath::module_directory (#880)
1 parent 2492bd2 commit f917412

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/cache/cached_path.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl CachedPath {
9999
cache: &Cache<Fs>,
100100
ctx: &mut Ctx,
101101
) -> Option<Self> {
102-
let cached_path = cache.value(&self.path.join(module_name));
102+
let cached_path = self.push(module_name, cache);
103103
cache.is_dir(&cached_path, ctx).then_some(cached_path)
104104
}
105105

@@ -122,12 +122,21 @@ impl CachedPath {
122122
})
123123
}
124124

125-
pub(crate) fn add_extension<Fs: FileSystem>(&self, ext: &str, cache: &Cache<Fs>) -> Self {
125+
pub(crate) fn push<Fs: FileSystem>(&self, target: &str, cache: &Cache<Fs>) -> Self {
126+
SCRATCH_PATH.with_borrow_mut(|path| {
127+
path.clear();
128+
path.push(&self.path);
129+
path.push(target);
130+
cache.value(path)
131+
})
132+
}
133+
134+
pub(crate) fn add_extension<Fs: FileSystem>(&self, target: &str, cache: &Cache<Fs>) -> Self {
126135
SCRATCH_PATH.with_borrow_mut(|path| {
127136
path.clear();
128137
let s = path.as_mut_os_string();
129138
s.push(self.path.as_os_str());
130-
s.push(ext);
139+
s.push(target);
131140
cache.value(path)
132141
})
133142
}

0 commit comments

Comments
 (0)