Skip to content

Commit f9b70ac

Browse files
committed
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);
1 parent 032804b commit f9b70ac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libcollections/vec.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl<T> FromIterator<T> for Vec<T> {
14291429
vector
14301430
}
14311431
};
1432-
vector.extend(iterable);
1432+
vector.extend_desugared(iterator);
14331433
vector
14341434
}
14351435
}
@@ -1466,9 +1466,14 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
14661466

14671467
#[unstable(feature = "collections", reason = "waiting on Extend stability")]
14681468
impl<T> Extend<T> for Vec<T> {
1469+
#[inline]
14691470
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
1470-
let mut iterator = iterable.into_iter();
1471+
self.extend_desugared(iterable.into_iter())
1472+
}
1473+
}
14711474

1475+
impl<T> Vec<T> {
1476+
fn extend_desugared<I: Iterator<Item=T>>(&mut self, mut iterator: I) {
14721477
// This function should be the moral equivalent of:
14731478
//
14741479
// for item in iterator {

0 commit comments

Comments
 (0)