We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4039a7f commit f90972aCopy full SHA for f90972a
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
@@ -99,6 +100,7 @@ where
99
100
fn next_chunk<const N: usize>(
101
&mut self,
102
) -> Result<[Self::Item; N], array::IntoIter<Self::Item, N>> {
103
+ // avoid codegen for the dead branch
104
let fun = const {
105
if crate::mem::needs_drop::<I::Item>() {
106
array::iter_next_chunk::<I::Item, N>
0 commit comments