about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-07 00:31:28 +0000
committerbors <bors@rust-lang.org>2014-09-07 00:31:28 +0000
commit09cebc25a31bc41447b7ebb47be162c04d64c198 (patch)
tree44e12b5b28db67496ca41509b7eb18778ffd760d /src/libcore
parent38eb0e551411ba0d175a55ed6d01bb529d1c8684 (diff)
parent7e12e67936dd2ad12e529278344dab369ccb75a0 (diff)
auto merge of #16999 : brson/rust/fannkuch, r=alexcrichton
From the discussion on reddit:
http://www.reddit.com/r/rust/comments/2fenlg/benchmark_improvement_fannkuchredux/

This adds two variants: the primary, that uses an unsafe block, and a secondary
that is completely safe.

The one with the unsafe block matches clang's performance and beats gcc's.
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;
         }
     }