Skip to content

Commit

Permalink
Use an iterator and extend.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltratt committed Nov 22, 2024
1 parent b9823e6 commit 2d37f94
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ fn compress<T: Clone + Copy + PartialEq>(
// `tmp` contains `(index, non-empty-value)` pairs that we can then pass to `fits`. Because
// this is such a tight loop, we reuse the same `Vec` to avoid repeated allocations.
tmp.clear();
for (i, v) in vec[s * row_length..(s + 1) * row_length].iter().enumerate() {
if *v != empty_val {
tmp.push((i, v));
}
}
tmp.extend(
vec[s * row_length..(s + 1) * row_length]
.iter()
.enumerate()
.filter(|(_, v)| **v != empty_val),
);

let mut d = 0; // displacement value
loop {
Expand Down

0 comments on commit 2d37f94

Please sign in to comment.