Skip to content

Commit

Permalink
improve clone_from_slice performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Orth committed Oct 11, 2014
1 parent cd1fa91 commit cea171b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libcore/slice.rs
Expand Up @@ -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
}
}

Expand Down

5 comments on commit cea171b

@bors
Copy link
Contributor

@bors bors commented on cea171b Oct 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at mahkoh@cea171b

@bors
Copy link
Contributor

@bors bors commented on cea171b Oct 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mahkoh/rust/clone_from_slice = cea171b into auto

@bors
Copy link
Contributor

@bors bors commented on cea171b Oct 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mahkoh/rust/clone_from_slice = cea171b merged ok, testing candidate = c53f8a9

@bors
Copy link
Contributor

@bors bors commented on cea171b Oct 24, 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 cea171b Oct 24, 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 = c53f8a9

Please sign in to comment.