Skip to content

Commit 7539517

Browse files
committed
add comment explaining optimization Filter::next_chunk
1 parent 59c95fd commit 7539517

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/core/src/iter/adapters/filter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ where
4141

4242
let result = self.iter.try_for_each(|element| {
4343
let idx = initialized;
44+
// branchless index update combined with unconditionally copying the value even when
45+
// it is filtered reduces branching and dependencies in the loop.
4446
initialized = idx + (self.predicate)(&element) as usize;
45-
4647
// SAFETY: Loop conditions ensure the index is in bounds.
4748
unsafe { array.get_unchecked_mut(idx) }.write(element);
4849

0 commit comments

Comments
 (0)