Skip to content

Commit 2d37f94

Browse files
committed
Use an iterator and extend.
1 parent b9823e6 commit 2d37f94

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ fn compress<T: Clone + Copy + PartialEq>(
183183
// `tmp` contains `(index, non-empty-value)` pairs that we can then pass to `fits`. Because
184184
// this is such a tight loop, we reuse the same `Vec` to avoid repeated allocations.
185185
tmp.clear();
186-
for (i, v) in vec[s * row_length..(s + 1) * row_length].iter().enumerate() {
187-
if *v != empty_val {
188-
tmp.push((i, v));
189-
}
190-
}
186+
tmp.extend(
187+
vec[s * row_length..(s + 1) * row_length]
188+
.iter()
189+
.enumerate()
190+
.filter(|(_, v)| **v != empty_val),
191+
);
191192

192193
let mut d = 0; // displacement value
193194
loop {

0 commit comments

Comments
 (0)