Move reset to seperate function (#10)

This commit is contained in:
Poliorcetics 2023-08-11 18:25:00 +02:00 committed by GitHub
parent 9c4b71027f
commit 7476504978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -157,11 +157,7 @@ impl<T: Sync + Send + 'static> Worker<T> {
// TODO: be smarter around reusing past results for rescoring // TODO: be smarter around reusing past results for rescoring
if self.pattern.cols.iter().all(|pat| pat.is_empty()) { if self.pattern.cols.iter().all(|pat| pat.is_empty()) {
self.matches.clear(); self.reset_matches();
self.matches
.extend((0..self.last_snapshot).map(|idx| Match { score: 0, idx }));
// there are usually only very few in flight items (one for each writer)
self.remove_in_flight_matches();
self.process_new_items_trivial(); self.process_new_items_trivial();
if self.should_notify.load(atomic::Ordering::Relaxed) { if self.should_notify.load(atomic::Ordering::Relaxed) {
(self.notify)(); (self.notify)();
@ -170,10 +166,7 @@ impl<T: Sync + Send + 'static> Worker<T> {
} }
if pattern_status == pattern::Status::Rescore { if pattern_status == pattern::Status::Rescore {
self.matches.clear(); self.reset_matches();
self.matches
.extend((0..self.last_snapshot).map(|idx| Match { score: 0, idx }));
self.remove_in_flight_matches();
} }
let mut unmatched = AtomicU32::new(0); let mut unmatched = AtomicU32::new(0);
@ -250,4 +243,12 @@ impl<T: Sync + Send + 'static> Worker<T> {
} }
} }
} }
fn reset_matches(&mut self) {
self.matches.clear();
self.matches
.extend((0..self.last_snapshot).map(|idx| Match { score: 0, idx }));
// there are usually only very few in flight items (one for each writer)
self.remove_in_flight_matches();
}
} }