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
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

5 comments on commit 026d206

@bors
Copy link
Contributor

@bors bors 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.

saw approval from alexcrichton
at stepancheg@026d206

@bors
Copy link
Contributor

@bors bors 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.

merging stepancheg/rust/push-all = 026d206 into auto

@bors
Copy link
Contributor

@bors bors 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/rust/push-all = 026d206 merged ok, testing candidate = af0783a

@bors
Copy link
Contributor

@bors bors 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.

@bors
Copy link
Contributor

@bors bors 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.

fast-forwarding master to auto = af0783a

Please sign in to comment.