We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 59c95fd commit 7539517Copy full SHA for 7539517
library/core/src/iter/adapters/filter.rs
@@ -41,8 +41,9 @@ where
41
42
let result = self.iter.try_for_each(|element| {
43
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.
46
initialized = idx + (self.predicate)(&element) as usize;
-
47
// SAFETY: Loop conditions ensure the index is in bounds.
48
unsafe { array.get_unchecked_mut(idx) }.write(element);
49
0 commit comments