diff --git a/matcher/src/fuzzy_optimal.rs b/matcher/src/fuzzy_optimal.rs index c3b7b96..749fa0c 100644 --- a/matcher/src/fuzzy_optimal.rs +++ b/matcher/src/fuzzy_optimal.rs @@ -64,7 +64,7 @@ impl Matcher { const UNMATCHED: ScoreCell = ScoreCell { score: 0, // if matched is true then the consecutive bonus - // is always alteast BONUS_CONSECUTIVE so + // is always atleast BONUS_CONSECUTIVE so // this constant can never occur naturally consecutive_bonus: 0, matched: true, diff --git a/src/lib.rs b/src/lib.rs index 866a036..29b1285 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,6 +90,7 @@ pub struct Nucleo { item_count: u32, pub matches: Vec, pub pattern: MultiPattern, + pub last_matched_pattern: MultiPattern, pub notify: Arc<(dyn Fn() + Sync + Send)>, items: Arc>, } @@ -110,6 +111,7 @@ impl Nucleo { pool, matches: Vec::with_capacity(2 * 1024), pattern: MultiPattern::new(&config, case_matching, columns as usize), + last_matched_pattern: MultiPattern::new(&config, case_matching, columns as usize), worker: Arc::new(Mutex::new(worker)), cleared: false, item_count: 0, @@ -195,6 +197,7 @@ impl Nucleo { inner.running = false; if !inner.was_canceled { self.item_count = inner.item_count(); + self.last_matched_pattern.clone_from(&inner.pattern); self.matches.clone_from(&inner.matches); } } diff --git a/src/pattern.rs b/src/pattern.rs index feb35ab..cc37fd6 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -165,11 +165,23 @@ pub enum Status { Rescore, } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct MultiPattern { pub cols: Vec, } +impl Clone for MultiPattern { + fn clone(&self) -> Self { + Self { + cols: self.cols.clone(), + } + } + + fn clone_from(&mut self, source: &Self) { + self.cols.clone_from(&source.cols) + } +} + impl MultiPattern { pub fn new( matcher_config: &MatcherConfig, @@ -205,7 +217,7 @@ impl MultiPattern { } } -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Pattern { terms: Vec, case_matching: CaseMatching, @@ -351,6 +363,24 @@ impl Pattern { } } +impl Clone for Pattern { + fn clone(&self) -> Self { + Self { + terms: self.terms.clone(), + case_matching: self.case_matching, + normalize: self.normalize, + status: self.status, + } + } + + fn clone_from(&mut self, source: &Self) { + self.terms.clone_from(&source.terms); + self.case_matching = source.case_matching; + self.normalize = source.normalize; + self.status = source.status; + } +} + fn pattern_atoms(pattern: &str) -> impl Iterator + '_ { let mut saw_backslash = false; pattern.split(move |c| {