Skip to content

Commit 026d206

Browse files
committed
Reimplement Vec::push_all* with .extend
It is shorter and also fixes missed reserve call.
1 parent 08e95a8 commit 026d206

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/libstd/vec.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ impl<T: Clone> Vec<T> {
230230
/// ```
231231
#[inline]
232232
pub fn push_all(&mut self, other: &[T]) {
233-
for element in other.iter() {
234-
self.push((*element).clone())
235-
}
233+
self.extend(other.iter().map(|e| e.clone()));
236234
}
237235

238236
/// Grows the `Vec` in-place.
@@ -947,9 +945,7 @@ impl<T> Vec<T> {
947945
/// assert_eq!(vec, vec!(~1, ~2, ~3, ~4));
948946
/// ```
949947
pub fn push_all_move(&mut self, other: Vec<T>) {
950-
for element in other.move_iter() {
951-
self.push(element)
952-
}
948+
self.extend(other.move_iter());
953949
}
954950

955951
/// Returns a mutable slice of `self` between `start` and `end`.

0 commit comments

Comments
 (0)