Skip to content
Merged
Prev Previous commit
Next Next commit
use cached self.globs
  • Loading branch information
RobinMalfait committed Apr 3, 2025
commit c80631d2314cc8a05246d87f282146b37091e940
23 changes: 17 additions & 6 deletions crates/oxide/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct Scanner {
dirs: Vec<PathBuf>,

/// All generated globs, used for setting up watchers
globs: Vec<GlobEntry>,
globs: Option<Vec<GlobEntry>>,

/// Track unique set of candidates
candidates: FxHashSet<String>,
Expand Down Expand Up @@ -296,16 +296,24 @@ impl Scanner {

#[tracing::instrument(skip_all)]
pub fn get_globs(&mut self) -> Vec<GlobEntry> {
if let Some(globs) = &self.globs {
return globs.clone();
}

self.scan_sources();

let mut globs = vec![];
for source in self.sources.iter() {
match source {
SourceEntry::Auto { base } | SourceEntry::External { base } => {
let globs = resolve_globs((base).to_path_buf(), &self.dirs, &self.extensions);
self.globs.extend(globs);
globs.extend(resolve_globs(
(base).to_path_buf(),
&self.dirs,
&self.extensions,
));
}
SourceEntry::Pattern { base, pattern } => {
self.globs.push(GlobEntry {
globs.push(GlobEntry {
base: base.to_string_lossy().to_string(),
pattern: pattern.to_string(),
});
Expand All @@ -315,9 +323,12 @@ impl Scanner {
}

// Re-optimize the globs to reduce the number of patterns we have to scan.
self.globs = optimize_patterns(&self.globs);
globs = optimize_patterns(&globs);

// Track the globs for subsequent calls
self.globs = Some(globs.clone());

self.globs.clone()
globs
}

#[tracing::instrument(skip_all)]
Expand Down