Skip to content

Commit

Permalink
Reimplement Vec::push_all* with .extend
Browse files Browse the repository at this point in the history
It is shorter and also fixes missed reserve call.
  • Loading branch information
stepancheg committed Apr 1, 2014
1 parent 08e95a8 commit 026d206
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down

2 comments on commit 026d206

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@radford
Copy link

@radford radford commented on 026d206 Apr 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stepancheg, could you update .grow() as well? Currently we are not checking for overflow as is done in reserve_additional.

Please sign in to comment.