diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-06-20 23:48:15 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-06-21 22:58:45 -0700 |
| commit | 47fa016193a729091aef9c531df9385548ad46ab (patch) | |
| tree | 9c2fdcbe55503be8d89c553a807ecc215cf2e567 /src/libcore/slice | |
| parent | 6de26f42deab53b1a8cbd57e4c696626e6650708 (diff) | |
Reuse the mem::swap optimizations to speed up slice::rotate
Exposes the swapping logic from PR 40454 as `pub unsafe fn ptr::swap_nonoverlapping` under feature swap_nonoverlapping This is most helpful for compound types where LLVM didn't vectorize the loop. Highlight: bench slice::rotate_medium_by727_strings gets 38% faster.
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/rotate.rs | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/libcore/slice/rotate.rs b/src/libcore/slice/rotate.rs index 3b9ae5652c5..e4a4e33c172 100644 --- a/src/libcore/slice/rotate.rs +++ b/src/libcore/slice/rotate.rs @@ -76,7 +76,7 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) { break; } - ptr_swap_n( + ptr::swap_nonoverlapping( mid.offset(-(left as isize)), mid.offset((right-delta) as isize), delta); @@ -103,10 +103,3 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) { ptr::copy_nonoverlapping(buf, mid.offset(-(left as isize)), right); } } - -unsafe fn ptr_swap_n<T>(a: *mut T, b: *mut T, n: usize) { - for i in 0..n { - // These are nonoverlapping, so use mem::swap instead of ptr::swap - mem::swap(&mut *a.offset(i as isize), &mut *b.offset(i as isize)); - } -} |
