From 026d206aa1e23a2496b5de47c0caf99024cc0f27 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Tue, 1 Apr 2014 20:16:59 +0000 Subject: [PATCH] Reimplement Vec::push_all* with .extend It is shorter and also fixes missed reserve call. --- src/libstd/vec.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 4dd1b5d08c0b9..69c3a85b2f160 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -230,9 +230,7 @@ impl Vec { /// ``` #[inline] pub fn push_all(&mut self, other: &[T]) { - for element in other.iter() { - self.push((*element).clone()) - } + self.extend(other.iter().map(|e| e.clone())); } /// Grows the `Vec` in-place. @@ -947,9 +945,7 @@ impl Vec { /// assert_eq!(vec, vec!(~1, ~2, ~3, ~4)); /// ``` pub fn push_all_move(&mut self, other: Vec) { - for element in other.move_iter() { - self.push(element) - } + self.extend(other.move_iter()); } /// Returns a mutable slice of `self` between `start` and `end`.