Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/matchers.rs @ 44597:e62052d0f377
rust-status: only involve ignore mechanism when needed
This prevents unnecessary fallbacks to Python, improving performance for
`hg update` for instance.
On Mozilla-Central a noop update goes from 1.6s down to 700ms.
Differential Revision: https://phab.mercurial-scm.org/D8315
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 20 Mar 2020 15:21:34 +0100 |
parents | 496868f1030c |
children | b15a37d85dbe 83c97c0bd319 |
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs Thu Mar 26 00:07:12 2020 +0900 +++ b/rust/hg-core/src/matchers.rs Fri Mar 20 15:21:34 2020 +0100 @@ -24,12 +24,12 @@ PatternSyntax, }; -use micro_timer::timed; +use std::borrow::ToOwned; use std::collections::HashSet; use std::fmt::{Display, Error, Formatter}; use std::iter::FromIterator; use std::ops::Deref; -use std::path::Path; +use std::path::{Path, PathBuf}; #[derive(Debug, PartialEq)] pub enum VisitChildrenSet<'a> { @@ -507,7 +507,8 @@ let mut prefixes = vec![]; for SubInclude { prefix, root, path } in subincludes.into_iter() { - let (match_fn, warnings) = get_ignore_function(&[path], root)?; + let (match_fn, warnings) = + get_ignore_function(vec![path.to_path_buf()], root)?; all_warnings.extend(warnings); prefixes.push(prefix.to_owned()); submatchers.insert(prefix.to_owned(), match_fn); @@ -578,12 +579,11 @@ /// Parses all "ignore" files with their recursive includes and returns a /// function that checks whether a given file (in the general sense) should be /// ignored. -#[timed] pub fn get_ignore_function<'a>( - all_pattern_files: &[impl AsRef<Path>], + all_pattern_files: Vec<PathBuf>, root_dir: impl AsRef<Path>, ) -> PatternResult<( - impl for<'r> Fn(&'r HgPath) -> bool + Sync, + Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>, Vec<PatternFileWarning>, )> { let mut all_patterns = vec![]; @@ -593,12 +593,15 @@ let (patterns, warnings) = get_patterns_from_file(pattern_file, &root_dir)?; - all_patterns.extend(patterns); + all_patterns.extend(patterns.to_owned()); all_warnings.extend(warnings); } let (matcher, warnings) = IncludeMatcher::new(all_patterns, root_dir)?; all_warnings.extend(warnings); - Ok((move |path: &HgPath| matcher.matches(path), all_warnings)) + Ok(( + Box::new(move |path: &HgPath| matcher.matches(path)), + all_warnings, + )) } impl<'a> IncludeMatcher<'a> {