perf: move to filter map from map and filter

This commit is contained in:
Ade Attwood 2023-11-30 14:07:00 +00:00
parent a4e674fddf
commit 863af1ce7b
2 changed files with 12 additions and 6 deletions

View file

@ -17,8 +17,7 @@ impl Matcher {
pub fn score(&self, text: &str) -> i64 { pub fn score(&self, text: &str) -> i64 {
self.matcher self.matcher
.fuzzy_indices(text, &self.pattern) .fuzzy_match(text, &self.pattern)
.map(|(score, _indices)| score)
.unwrap_or_default() .unwrap_or_default()
} }
} }

View file

@ -25,12 +25,19 @@ pub fn sort_strings(options: Options, strings: Vec<String>) -> Vec<Match> {
let mut matches = strings let mut matches = strings
.into_par_iter() .into_par_iter()
.map(|candidate| Match { .filter_map(|candidate| {
score: matcher.score(candidate.as_str()), let score = matcher.score(candidate.as_str());
content: candidate, if score > options.minimum_score {
return None;
}
Some(Match {
score,
content: candidate,
})
}) })
.filter(|m| m.score > options.minimum_score)
.collect::<Vec<Match>>(); .collect::<Vec<Match>>();
matches.par_sort_unstable_by(|a, b| a.score.cmp(&b.score)); matches.par_sort_unstable_by(|a, b| a.score.cmp(&b.score));
matches matches
} }