Skip to content

Commit

Permalink
Optimize Slice::reverse
Browse files Browse the repository at this point in the history
This makes the completely safe implementation of fannkuchredux perform
the same as C++. Yay, Rust.
  • Loading branch information
brson committed Sep 5, 2014
1 parent fc3b638 commit 7e12e67
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 197 deletions.
1 change: 0 additions & 1 deletion src/etc/licenseck.py
Expand Up @@ -44,7 +44,6 @@
"libsync/mpsc_intrusive.rs", # BSD
"test/bench/shootout-binarytrees.rs", # BSD
"test/bench/shootout-fannkuch-redux.rs", # BSD
"test/bench/shootout-fannkuch-redux-safe.rs", # BSD
"test/bench/shootout-k-nucleotide.rs", # BSD
"test/bench/shootout-mandelbrot.rs", # BSD
"test/bench/shootout-meteor.rs", # BSD
Expand Down
7 changes: 6 additions & 1 deletion src/libcore/slice.rs
Expand Up @@ -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;
}
}
Expand Down
188 changes: 0 additions & 188 deletions src/test/bench/shootout-fannkuch-redux-safe.rs

This file was deleted.

8 changes: 1 addition & 7 deletions src/test/bench/shootout-fannkuch-redux.rs
Expand Up @@ -125,13 +125,7 @@ impl Perm {


fn reverse(tperm: &mut [i32], mut k: uint) {
let p = tperm.as_mut_ptr();

unsafe {
for off in range(0, k as int / 2) {
std::ptr::swap(p.offset(off), p.offset(k as int - 1 - off));
}
}
tperm.mut_slice_to(k).reverse()
}

fn work(mut perm: Perm, n: uint, max: uint) -> (i32, i32) {
Expand Down

9 comments on commit 7e12e67

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 6, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at brson@7e12e67

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 6, 2014

Choose a reason for hiding this comment

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

merging brson/rust/fannkuch = 7e12e67 into auto

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 6, 2014

Choose a reason for hiding this comment

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

brson/rust/fannkuch = 7e12e67 merged ok, testing candidate = 8e8c6f28

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 7, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at brson@7e12e67

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 7, 2014

Choose a reason for hiding this comment

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

merging brson/rust/fannkuch = 7e12e67 into auto

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 7, 2014

Choose a reason for hiding this comment

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

brson/rust/fannkuch = 7e12e67 merged ok, testing candidate = 09cebc2

@bors
Copy link
Contributor

@bors bors commented on 7e12e67 Sep 7, 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 = 09cebc2

Please sign in to comment.