Add Extend::{extend_one,extend_reserve}
This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
This commit is contained in:
parent
4bd32c9804
commit
6700e18688
21 changed files with 251 additions and 5 deletions
|
@ -2045,6 +2045,16 @@ impl<T> Extend<T> for Vec<T> {
|
|||
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
|
||||
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn extend_one(&mut self, item: T) {
|
||||
self.push(item);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn extend_reserve(&mut self, additional: usize) {
|
||||
self.reserve(additional);
|
||||
}
|
||||
}
|
||||
|
||||
// Specialization trait used for Vec::from_iter and Vec::extend
|
||||
|
@ -2316,6 +2326,16 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
|
|||
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
|
||||
self.spec_extend(iter.into_iter())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn extend_one(&mut self, &item: &'a T) {
|
||||
self.push(item);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn extend_reserve(&mut self, additional: usize) {
|
||||
self.reserve(additional);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! __impl_slice_eq1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue