summaryrefslogtreecommitdiffstats
path: root/ignore
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-04-24 10:42:19 -0400
committerAndrew Gallant <jamslam@gmail.com>2018-04-24 11:19:03 -0400
commitab64da73ab3f73f50192459dfc1e49c6cabd9de8 (patch)
tree783fb638506f87a1459f194f1baebab85f2c1511 /ignore
parent1266de3d4c82f281642ba0f4b59827091a55c8fc (diff)
ignore: speed up Gitignore::empty
This commit makes Gitignore::empty a bit faster by avoiding allocation and manually specializing the implementation instead of routing it through the GitignoreBuilder. This helps improve uses of ripgrep that traverse *many* directories, and in particular, when the use of ignores is disabled via command line switches. Fixes #835, Closes #836
Diffstat (limited to 'ignore')
-rw-r--r--ignore/src/dir.rs4
-rw-r--r--ignore/src/gitignore.rs15
2 files changed, 14 insertions, 5 deletions
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<Error>) {
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<Glob>,
num_ignores: u64,
num_whitelists: u64,
- matches: Arc<ThreadLocal<RefCell<Vec<usize>>>>,
+ matches: Option<Arc<ThreadLocal<RefCell<Vec<usize>>>>>,
}
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())),
})
}