Skip to content

Commit c80631d

Browse files
committed
use cached self.globs
1 parent a63b1fa commit c80631d

File tree

1 file changed

+17
-6
lines changed
  • crates/oxide/src/scanner

1 file changed

+17
-6
lines changed

crates/oxide/src/scanner/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct Scanner {
9393
dirs: Vec<PathBuf>,
9494

9595
/// All generated globs, used for setting up watchers
96-
globs: Vec<GlobEntry>,
96+
globs: Option<Vec<GlobEntry>>,
9797

9898
/// Track unique set of candidates
9999
candidates: FxHashSet<String>,
@@ -296,16 +296,24 @@ impl Scanner {
296296

297297
#[tracing::instrument(skip_all)]
298298
pub fn get_globs(&mut self) -> Vec<GlobEntry> {
299+
if let Some(globs) = &self.globs {
300+
return globs.clone();
301+
}
302+
299303
self.scan_sources();
300304

305+
let mut globs = vec![];
301306
for source in self.sources.iter() {
302307
match source {
303308
SourceEntry::Auto { base } | SourceEntry::External { base } => {
304-
let globs = resolve_globs((base).to_path_buf(), &self.dirs, &self.extensions);
305-
self.globs.extend(globs);
309+
globs.extend(resolve_globs(
310+
(base).to_path_buf(),
311+
&self.dirs,
312+
&self.extensions,
313+
));
306314
}
307315
SourceEntry::Pattern { base, pattern } => {
308-
self.globs.push(GlobEntry {
316+
globs.push(GlobEntry {
309317
base: base.to_string_lossy().to_string(),
310318
pattern: pattern.to_string(),
311319
});
@@ -315,9 +323,12 @@ impl Scanner {
315323
}
316324

317325
// Re-optimize the globs to reduce the number of patterns we have to scan.
318-
self.globs = optimize_patterns(&self.globs);
326+
globs = optimize_patterns(&globs);
327+
328+
// Track the globs for subsequent calls
329+
self.globs = Some(globs.clone());
319330

320-
self.globs.clone()
331+
globs
321332
}
322333

323334
#[tracing::instrument(skip_all)]

0 commit comments

Comments
 (0)