Skip to content

Commit 2b84507

Browse files
authored
Rollup merge of #54761 - Lucretiel:patch-1, r=cramertj
Make spec_extend use for_each() `for_each` will use an iterator's own implementation of `try_fold`, which I understand to be generally preferable (because nested iterator adapter's will use each other's `try_fold` and be designed for the specific adaptation in a way that promotes performance and inlining.
2 parents 8b9145e + ec59188 commit 2b84507

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/liballoc/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1822,12 +1822,12 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
18221822
unsafe {
18231823
let mut ptr = self.as_mut_ptr().add(self.len());
18241824
let mut local_len = SetLenOnDrop::new(&mut self.len);
1825-
for element in iterator {
1825+
iterator.for_each(move |element| {
18261826
ptr::write(ptr, element);
18271827
ptr = ptr.offset(1);
18281828
// NB can't overflow since we would have had to alloc the address space
18291829
local_len.increment_len(1);
1830-
}
1830+
});
18311831
}
18321832
} else {
18331833
self.extend_desugared(iterator)

0 commit comments

Comments
 (0)