improve clone_from_slice performance

This commit is contained in:
Julian Orth 2014-10-12 01:17:11 +02:00
parent cd1fa91d2b
commit cea171b0ae

View File

@ -1126,13 +1126,16 @@ pub trait MutableCloneableSlice<T> {
}
#[unstable = "trait is unstable"]
impl<'a, T:Clone> MutableCloneableSlice<T> for &'a mut [T] {
impl<'a, T: Clone> MutableCloneableSlice<T> for &'a mut [T] {
#[inline]
fn clone_from_slice(self, src: &[T]) -> uint {
for (a, b) in self.iter_mut().zip(src.iter()) {
a.clone_from(b);
let min = cmp::min(self.len(), src.len());
let dst = self.slice_to_mut(min);
let src = src.slice_to(min);
for i in range(0, min) {
dst[i].clone_from(&src[i]);
}
cmp::min(self.len(), src.len())
min
}
}