Reimplement Vec::push_all* with .extend
It is shorter and also fixes missed reserve call.
This commit is contained in:
parent
08e95a87b8
commit
026d206aa1
|
@ -230,9 +230,7 @@ impl<T: Clone> Vec<T> {
|
|||
/// ```
|
||||
#[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<T> Vec<T> {
|
|||
/// assert_eq!(vec, vec!(~1, ~2, ~3, ~4));
|
||||
/// ```
|
||||
pub fn push_all_move(&mut self, other: Vec<T>) {
|
||||
for element in other.move_iter() {
|
||||
self.push(element)
|
||||
}
|
||||
self.extend(other.move_iter());
|
||||
}
|
||||
|
||||
/// Returns a mutable slice of `self` between `start` and `end`.
|
||||
|
|
Loading…
Reference in New Issue