From f9b70acfd4167f5911c1be4e2dc960c370adb266 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Sun, 22 Feb 2015 19:22:50 +0200 Subject: [PATCH] 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); --- src/libcollections/vec.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3db55b82fe8..3ed9c154e47 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1429,7 +1429,7 @@ fn from_iter>(iterable: I) -> Vec { 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 Extend for Vec { + #[inline] fn extend>(&mut self, iterable: I) { - let mut iterator = iterable.into_iter(); + self.extend_desugared(iterable.into_iter()) + } +} +impl Vec { + fn extend_desugared>(&mut self, mut iterator: I) { // This function should be the moral equivalent of: // // for item in iterator {