diff options
| -rw-r--r-- | src/libcollections/lib.rs | 2 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 12 |
2 files changed, 5 insertions, 9 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 34bd1345fcb..03ee8ba31b1 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -62,7 +62,7 @@ #![feature(unsafe_no_drop_flag, filling_drop)] #![feature(decode_utf16)] #![feature(utf8_error)] -#![cfg_attr(test, feature(rand, test))] +#![cfg_attr(test, feature(clone_from_slice, rand, test))] #![feature(no_std)] #![no_std] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 4110faa41b3..de3e6f94e87 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1007,19 +1007,15 @@ impl<T:Clone> Clone for Vec<T> { fn clone_from(&mut self, other: &Vec<T>) { // drop anything in self that will not be overwritten - if self.len() > other.len() { - self.truncate(other.len()) - } + self.truncate(other.len()); + let len = self.len(); // reuse the contained values' allocations/resources. - for (place, thing) in self.iter_mut().zip(other) { - place.clone_from(thing) - } + self.clone_from_slice(&other[..len]); // self.len <= other.len due to the truncate above, so the // slice here is always in-bounds. - let slice = &other[self.len()..]; - self.push_all(slice); + self.push_all(&other[len..]); } } |
