Skip to content

Commit

Permalink
Rollup merge of rust-lang#54761 - Lucretiel:patch-1, r=cramertj
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pietroalbini authored Oct 3, 2018
2 parents 36e7d4d + ec59188 commit 11ef111
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,12 +1822,12 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len());
let mut local_len = SetLenOnDrop::new(&mut self.len);
for element in iterator {
iterator.for_each(move |element| {
ptr::write(ptr, element);
ptr = ptr.offset(1);
// NB can't overflow since we would have had to alloc the address space
local_len.increment_len(1);
}
});
}
} else {
self.extend_desugared(iterator)
Expand Down

0 comments on commit 11ef111

Please sign in to comment.