diff options
author | jhspetersson <jhspetersson@gmail.com> | 2024-01-06 01:06:12 +0100 |
---|---|---|
committer | jhspetersson <jhspetersson@gmail.com> | 2024-01-06 01:06:12 +0100 |
commit | 32d20485a4858a68d0afcd043c8972e915ae9a10 (patch) | |
tree | 67218be442d6ff7ea5d88c811aabe5c5b8b18410 | |
parent | 801cc4ab96c3ca26b5bc52c6c717f5d3e18be17a (diff) |
misc optimizations
-rw-r--r-- | src/ignore/git.rs | 26 | ||||
-rw-r--r-- | src/searcher.rs | 7 |
2 files changed, 10 insertions, 23 deletions
diff --git a/src/ignore/git.rs b/src/ignore/git.rs index 3e93f3f..a30c63f 100644 --- a/src/ignore/git.rs +++ b/src/ignore/git.rs @@ -50,18 +50,12 @@ pub fn update_gitignore_map(gitignore_map: &mut HashMap<PathBuf, Vec<GitignoreFi } pub fn get_gitignore_filters(gitignore_map: &mut HashMap<PathBuf, Vec<GitignoreFilter>>, dir: &Path) -> Vec<GitignoreFilter> { - let mut result = vec![]; - - for (dir_path, regexes) in &mut *gitignore_map { - if dir.to_path_buf() == *dir_path { - for ref mut rx in regexes { - result.push(rx.clone()); - } - - return result; - } + if let Some(regexes) = gitignore_map.get(&dir.to_path_buf()) { + return regexes.to_vec(); } + let mut result = vec![]; + let mut path = dir.to_path_buf(); loop { @@ -71,16 +65,8 @@ pub fn get_gitignore_filters(gitignore_map: &mut HashMap<PathBuf, Vec<GitignoreF return result; } - for (dir_path, regexes) in &mut *gitignore_map { - if path == *dir_path { - let mut tmp = vec![]; - for ref mut rx in regexes { - tmp.push(rx.clone()); - } - tmp.append(&mut result); - result.clear(); - result.append(&mut tmp); - } + if let Some(regexes) = gitignore_map.get(&path) { + result = vec![regexes.to_vec(), result].concat(); } } } diff --git a/src/searcher.rs b/src/searcher.rs index c0929ea..5324b6d 100644 --- a/src/searcher.rs +++ b/src/searcher.rs @@ -14,6 +14,7 @@ use std::os::unix::fs::DirEntryExt; use std::os::unix::fs::MetadataExt; use std::path::Path; use std::path::PathBuf; +use std::rc::Rc; use chrono::{DateTime, Local}; use lscolors::{LsColors, Style}; @@ -60,7 +61,7 @@ pub struct Searcher<'a> { regex_cache: HashMap<String, Regex>, found: u32, raw_output_buffer: Vec<HashMap<String, String>>, - partitioned_output_buffer: HashMap<Vec<String>, Vec<HashMap<String, String>>>, + partitioned_output_buffer: Rc<HashMap<Vec<String>, Vec<HashMap<String, String>>>>, output_buffer: TopN<Criteria<String>, String>, gitignore_map: HashMap<PathBuf, Vec<GitignoreFilter>>, hgignore_filters: Vec<HgignoreFilter>, @@ -108,7 +109,7 @@ impl <'a> Searcher<'a> { regex_cache: HashMap::new(), found: 0, raw_output_buffer: vec![], - partitioned_output_buffer: HashMap::new(), + partitioned_output_buffer: Rc::new(HashMap::new()), output_buffer: if limit == 0 { TopN::limitless() } else { TopN::new(limit) }, gitignore_map: HashMap::new(), hgignore_filters: vec![], @@ -313,7 +314,7 @@ impl <'a> Searcher<'a> { if self.has_aggregate_column() { if !self.query.grouping_fields.is_empty() { if self.partitioned_output_buffer.is_empty() { - self.partitioned_output_buffer = self.partition_output_buffer(); + self.partitioned_output_buffer = Rc::new(self.partition_output_buffer()); } let group_keys: Vec<String> = self.query.grouping_fields.iter().map(|f| f.to_string()).collect(); |