perf: move to filter map from map and filter
This commit is contained in:
parent
a4e674fddf
commit
863af1ce7b
2 changed files with 12 additions and 6 deletions
|
|
@ -17,8 +17,7 @@ impl Matcher {
|
|||
|
||||
pub fn score(&self, text: &str) -> i64 {
|
||||
self.matcher
|
||||
.fuzzy_indices(text, &self.pattern)
|
||||
.map(|(score, _indices)| score)
|
||||
.fuzzy_match(text, &self.pattern)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,12 +25,19 @@ pub fn sort_strings(options: Options, strings: Vec<String>) -> Vec<Match> {
|
|||
|
||||
let mut matches = strings
|
||||
.into_par_iter()
|
||||
.map(|candidate| Match {
|
||||
score: matcher.score(candidate.as_str()),
|
||||
content: candidate,
|
||||
.filter_map(|candidate| {
|
||||
let score = matcher.score(candidate.as_str());
|
||||
if score > options.minimum_score {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(Match {
|
||||
score,
|
||||
content: candidate,
|
||||
})
|
||||
})
|
||||
.filter(|m| m.score > options.minimum_score)
|
||||
.collect::<Vec<Match>>();
|
||||
|
||||
matches.par_sort_unstable_by(|a, b| a.score.cmp(&b.score));
|
||||
matches
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue