Skip to content

Commit

Permalink
use more efficient method of windowing slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Borcherding committed Nov 25, 2024
1 parent 04caa1d commit 40fae3e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/encoding/match_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'data> MatchGenerator<'data> {
self.last_idx_in_sequence = self.suffix_idx;
} else {
let last_entry = self.window.last_mut().unwrap();
let key = &last_entry.data[..MIN_MATCH_LEN];
let key = &last_entry.data[self.suffix_idx..self.suffix_idx+MIN_MATCH_LEN];
if !last_entry.suffixes.contains_key(&key) {
last_entry.suffixes.insert(key, self.suffix_idx);
}
Expand All @@ -141,11 +141,10 @@ impl<'data> MatchGenerator<'data> {
if last_entry.data.len() < MIN_MATCH_LEN {
return;
}
let last_idx = usize::min(idx, last_entry.data.len() - MIN_MATCH_LEN);
for idx in self.suffix_idx..=last_idx {
let key = &last_entry.data[idx..idx + MIN_MATCH_LEN];
let slice = &last_entry.data[self.suffix_idx..idx];
for (key_index, key) in slice.windows(MIN_MATCH_LEN).enumerate() {
if !last_entry.suffixes.contains_key(&key) {
last_entry.suffixes.insert(key, idx);
last_entry.suffixes.insert(key, self.suffix_idx + key_index);
}
}
}
Expand Down

0 comments on commit 40fae3e

Please sign in to comment.