about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcore/slice.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index 583bb57a4a6..6107564b4ae 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -478,8 +478,13 @@ impl<T> SliceExt for [T] {
     fn clone_from_slice(&mut self, src: &[T]) where T: Clone {
         assert!(self.len() == src.len(),
                 "destination and source slices have different lengths");
-        for (dst, src) in self.iter_mut().zip(src) {
-            dst.clone_from(src);
+        // NOTE: We need to explicitly slice them to the same length
+        // for bounds checking to be elided, and the optimizer will
+        // generate memcpy for simple cases (for example T = u8).
+        let len = self.len();
+        let src = &src[..len];
+        for i in 0..len {
+            self[i].clone_from(&src[i]);
         }
     }
 }