about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMikhail Zabaluev <mikhail.zabaluev@gmail.com>2015-02-22 19:22:50 +0200
committerMikhail Zabaluev <mikhail.zabaluev@gmail.com>2015-02-22 20:42:35 +0200
commitf9b70acfd4167f5911c1be4e2dc960c370adb266 (patch)
tree4895571d488b6a7b36efe4aa05a1b3bda339699c
parent032804bf68e2ac13add895206f2173409acff836 (diff)
downloadrust-f9b70acfd4167f5911c1be4e2dc960c370adb266.tar.gz
rust-f9b70acfd4167f5911c1be4e2dc960c370adb266.zip
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);
-rw-r--r--src/libcollections/vec.rs9
1 files 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 @@ impl<T> FromIterator<T> for Vec<T> {
                 vector
             }
         };
-        vector.extend(iterable);
+        vector.extend_desugared(iterator);
         vector
     }
 }
@@ -1466,9 +1466,14 @@ impl<'a, T> IntoIterator for &'a mut Vec<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 {