Desugar the implementation of extend to work with Iterator
Implement both Vec::from_iter and extend in terms of an internal method working with Iterator. Otherwise, the code below ends up using two monomorphizations of extend, differing only in the implementation of IntoIterator: let mut v = Vector::from_iter(iterable1); v.extend(iterable2);
This commit is contained in:
parent
032804bf68
commit
f9b70acfd4
@ -1429,7 +1429,7 @@ fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> Vec<T> {
|
||||
vector
|
||||
}
|
||||
};
|
||||
vector.extend(iterable);
|
||||
vector.extend_desugared(iterator);
|
||||
vector
|
||||
}
|
||||
}
|
||||
@ -1466,9 +1466,14 @@ fn into_iter(mut self) -> slice::IterMut<'a, T> {
|
||||
|
||||
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
|
||||
impl<T> Extend<T> for Vec<T> {
|
||||
#[inline]
|
||||
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
|
||||
let mut iterator = iterable.into_iter();
|
||||
self.extend_desugared(iterable.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Vec<T> {
|
||||
fn extend_desugared<I: Iterator<Item=T>>(&mut self, mut iterator: I) {
|
||||
// This function should be the moral equivalent of:
|
||||
//
|
||||
// for item in iterator {
|
||||
|
Loading…
Reference in New Issue
Block a user