diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-01-08 12:18:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 17:18:42 +0000 |
commit | e212e1fc35ddae63f457f0f2a2e95154e008941f (patch) | |
tree | 6c1f553fbc529bfcab6413049af8f32ed31d1dfd /cli/args/flags.rs | |
parent | ee45d5bf8f2e1826b2a106b030abe891cfc0b37c (diff) |
perf: skip expanding exclude globs (#21817)
We were calling `expand_glob` on our excludes, which is very expensive
and unnecessary because we can pattern match while traversing instead.
1. Doesn't expand "exclude" globs. Instead pattern matches while walking
the directory.
2. Splits up the "include" into base paths and applicable file patterns.
This causes less pattern matching to occur because we're only pattern
matching on patterns that might match and not ones in completely
unrelated directories.
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 8b796edc2..a05d31ce1 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -34,6 +34,35 @@ pub struct FileFlags { pub include: Vec<PathBuf>, } +impl FileFlags { + pub fn with_absolute_paths(self, base: &Path) -> Self { + fn to_absolute_path(path: PathBuf, base: &Path) -> PathBuf { + // todo(dsherret): don't store URLs in PathBufs + if path.starts_with("http:") + || path.starts_with("https:") + || path.starts_with("file:") + { + path + } else { + base.join(path) + } + } + + Self { + include: self + .include + .into_iter() + .map(|p| to_absolute_path(p, base)) + .collect(), + ignore: self + .ignore + .into_iter() + .map(|p| to_absolute_path(p, base)) + .collect(), + } + } +} + #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct BenchFlags { pub files: FileFlags, |