Skip to content

Commit f978c77

Browse files
committed
Incorporated review feedback atop pcwalton's original patches.
(Original PR was rust-lang#12716; feedback was provided by thestinger and me.)
1 parent 15d9acc commit f978c77

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libstd/vec_ng.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
use cast::{forget, transmute};
1515
use clone::Clone;
1616
use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd};
17-
use container::Container;
17+
use container::{Container, Mutable};
1818
use default::Default;
1919
use fmt;
20-
use iter::{DoubleEndedIterator, FromIterator, Extendable, Iterator};
20+
use iter::{DoubleEndedIterator, FromIterator, Extendable, Iterator, Rev};
2121
use libc::{free, c_void};
2222
use mem::{size_of, move_val_init};
2323
use mem;
@@ -68,11 +68,7 @@ impl<T> Vec<T> {
6868

6969
impl<T: Clone> Vec<T> {
7070
pub fn from_slice(values: &[T]) -> Vec<T> {
71-
let mut vector = Vec::new();
72-
for value in values.iter() {
73-
vector.push((*value).clone())
74-
}
75-
vector
71+
values.iter().map(|x| x.clone()).collect()
7672
}
7773

7874
pub fn from_elem(length: uint, value: T) -> Vec<T> {
@@ -292,9 +288,8 @@ impl<T> Vec<T> {
292288
}
293289

294290
#[inline]
295-
pub fn move_rev_iter(mut self) -> MoveItems<T> {
296-
self.reverse();
297-
self.move_iter()
291+
pub fn move_rev_iter(self) -> Rev<MoveItems<T>> {
292+
self.move_iter().rev()
298293
}
299294

300295
#[inline]
@@ -437,9 +432,12 @@ impl<T> Vec<T> {
437432
pub fn as_ptr(&self) -> *T {
438433
self.as_slice().as_ptr()
439434
}
435+
}
440436

437+
impl<T> Mutable for Vec<T> {
438+
/// Clear the vector, removing all values.
441439
#[inline]
442-
pub fn clear(&mut self) {
440+
fn clear(&mut self) {
443441
self.truncate(0)
444442
}
445443
}

0 commit comments

Comments
 (0)