perf: add instance prop of SkimMatcherV2
This is so we are not crating an new instance of this each time we are scoring a match.
This commit is contained in:
parent
9fdb633f3e
commit
f4a65a574c
3 changed files with 11 additions and 4 deletions
|
|
@ -41,7 +41,7 @@ pub extern "C" fn ivy_match(c_pattern: *const c_char, c_text: *const c_char) ->
|
|||
let pattern = to_string(c_pattern);
|
||||
let text = to_string(c_text);
|
||||
|
||||
let m = matcher::Matcher{ pattern };
|
||||
let m = matcher::Matcher::new( pattern );
|
||||
return m.score(text) as i32;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,19 @@ use fuzzy_matcher::skim::SkimMatcherV2;
|
|||
pub struct Matcher {
|
||||
/// The search pattern that we want to match against some text
|
||||
pub pattern: String,
|
||||
matcher: SkimMatcherV2,
|
||||
}
|
||||
|
||||
impl Matcher {
|
||||
pub fn new(pattern: String) -> Self {
|
||||
return Self {
|
||||
pattern,
|
||||
matcher: SkimMatcherV2::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn score(self: &Self, text: String) -> i64 {
|
||||
let matcher = SkimMatcherV2::default();
|
||||
if let Some((score, _indices)) = matcher.fuzzy_indices(&text, &self.pattern) {
|
||||
if let Some((score, _indices)) = self.matcher.fuzzy_indices(&text, &self.pattern) {
|
||||
return score;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl Options {
|
|||
|
||||
pub fn sort_strings(options: Options, strings: Vec<String>) -> Arc<Mutex<Vec<Match>>> {
|
||||
let matches: Arc<Mutex<Vec<Match>>> = Arc::new(Mutex::new(Vec::new()));
|
||||
let matcher = Arc::new(Mutex::new(matcher::Matcher{ pattern: options.pattern }));
|
||||
let matcher = Arc::new(Mutex::new(matcher::Matcher::new(options.pattern)));
|
||||
|
||||
let pool = thread_pool::ThreadPool::new(std::thread::available_parallelism().unwrap().get());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue