File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
library/core/src/iter/adapters Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change 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
99100 fn next_chunk < const N : usize > (
100101 & mut self ,
101102 ) -> Result < [ Self :: Item ; N ] , array:: IntoIter < Self :: Item , N > > {
103+ // avoid codegen for the dead branch
102104 let fun = const {
103105 if crate :: mem:: needs_drop :: < I :: Item > ( ) {
104106 array:: iter_next_chunk :: < I :: Item , N >
You can’t perform that action at this time.
0 commit comments