Skip to content

Commit

Permalink
auto merge of #17960 : mahkoh/rust/clone_from_slice, r=pcwalton
Browse files Browse the repository at this point in the history
Old vs. New vs. Vec::push_all

```
test slice     ... bench:   3091942 ns/iter (+/- 54460)
test slice_new ... bench:   1800065 ns/iter (+/- 69513)
test vec       ... bench:   1804805 ns/iter (+/- 75609)
```
  • Loading branch information
bors committed Oct 24, 2014
2 parents 56d544f + cea171b commit c53f8a9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,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
}
}

Expand Down

0 comments on commit c53f8a9

Please sign in to comment.