about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2014-09-04 19:54:41 -0700
committerBrian Anderson <banderson@mozilla.com>2014-09-05 14:12:20 -0700
commit7e12e67936dd2ad12e529278344dab369ccb75a0 (patch)
tree326c9ad50a58c80621364dabedfe9105f1dec51b /src/libcore
parentfc3b6383ba346dcf243d189fa2d87e2b5f2b9f61 (diff)
Optimize Slice::reverse
This makes the completely safe implementation of fannkuchredux perform
the same as C++. Yay, Rust.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/slice.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index c3c18e36617..cc2b01e3bb5 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -806,7 +806,12 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
         let mut i: uint = 0;
         let ln = self.len();
         while i < ln / 2 {
-            self.swap(i, ln - i - 1);
+            // Unsafe swap to avoid the bounds check in safe swap.
+            unsafe {
+                let pa: *mut T = self.unsafe_mut_ref(i);
+                let pb: *mut T = self.unsafe_mut_ref(ln - i - 1);
+                ptr::swap(pa, pb);
+            }
             i += 1;
         }
     }