diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a486e98..d872c472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ Bug fixes: Fix problems with `--line-number-width` by removing it. * [BUG #832](https://github.com/BurntSushi/ripgrep/issues/832): Clarify usage instructions for `-f/--file` flag. +* [BUG #835](https://github.com/BurntSushi/ripgrep/issues/835): + Fix small performance regression while crawling very large directory trees. * [BUG #851](https://github.com/BurntSushi/ripgrep/issues/851): Fix `-S/--smart-case` detection once and for all. * [BUG #852](https://github.com/BurntSushi/ripgrep/issues/852): diff --git a/globset/src/lib.rs b/globset/src/lib.rs index eabed515..50c92e42 100644 --- a/globset/src/lib.rs +++ b/globset/src/lib.rs @@ -288,6 +288,14 @@ pub struct GlobSet { } impl GlobSet { + /// Create an empty `GlobSet`. An empty set matches nothing. + pub fn empty() -> GlobSet { + GlobSet { + len: 0, + strats: vec![], + } + } + /// Returns true if this set is empty, and therefore matches nothing. pub fn is_empty(&self) -> bool { self.len == 0 diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs index 13065c3d..2e1b82e2 100644 --- a/ignore/src/dir.rs +++ b/ignore/src/dir.rs @@ -209,7 +209,9 @@ impl Ignore { fn add_child_path(&self, dir: &Path) -> (IgnoreInner, Option) { let mut errs = PartialErrorBuilder::default(); let custom_ig_matcher = - { + if self.0.custom_ignore_filenames.is_empty() { + Gitignore::empty() + } else { let (m, err) = create_gitignore(&dir, &self.0.custom_ignore_filenames); errs.maybe_push(err); diff --git a/ignore/src/gitignore.rs b/ignore/src/gitignore.rs index 67d5a752..abcb3685 100644 --- a/ignore/src/gitignore.rs +++ b/ignore/src/gitignore.rs @@ -83,7 +83,7 @@ pub struct Gitignore { globs: Vec, num_ignores: u64, num_whitelists: u64, - matches: Arc>>>, + matches: Option>>>>, } impl Gitignore { @@ -143,7 +143,14 @@ impl Gitignore { /// /// Its path is empty. pub fn empty() -> Gitignore { - GitignoreBuilder::new("").build().unwrap() + Gitignore { + set: GlobSet::empty(), + root: PathBuf::from(""), + globs: vec![], + num_ignores: 0, + num_whitelists: 0, + matches: None, + } } /// Returns the directory containing this gitignore matcher. @@ -249,7 +256,7 @@ impl Gitignore { return Match::None; } let path = path.as_ref(); - let _matches = self.matches.get_default(); + let _matches = self.matches.as_ref().unwrap().get_default(); let mut matches = _matches.borrow_mut(); let candidate = Candidate::new(path); self.set.matches_candidate_into(&candidate, &mut *matches); @@ -345,7 +352,7 @@ impl GitignoreBuilder { globs: self.globs.clone(), num_ignores: nignore as u64, num_whitelists: nwhite as u64, - matches: Arc::new(ThreadLocal::default()), + matches: Some(Arc::new(ThreadLocal::default())), }) }