diff options
| author | Djzin <djzin@users.noreply.github.com> | 2017-05-28 18:10:12 +0100 |
|---|---|---|
| committer | Djzin <djzin@users.noreply.github.com> | 2017-05-28 18:10:12 +0100 |
| commit | b795b7b43b5812a07b8fa7ed022b2f0f012a4950 (patch) | |
| tree | 8de5392f10b2f296c149ea0f9963c453a7f66b5f | |
| parent | 8a973dfa24b676e6e50b6c6bbb1cdce17499a2f7 (diff) | |
| download | rust-b795b7b43b5812a07b8fa7ed022b2f0f012a4950.tar.gz rust-b795b7b43b5812a07b8fa7ed022b2f0f012a4950.zip | |
restore old behaviour
| -rw-r--r-- | src/libcore/mem.rs | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 93ec54b1739..91b348fb5d6 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -499,24 +499,6 @@ pub unsafe fn uninitialized<T>() -> T { #[stable(feature = "rust1", since = "1.0.0")] pub fn swap<T>(x: &mut T, y: &mut T) { unsafe { - let len = size_of::<T>(); - - if len < 128 { - // Give ourselves some scratch space to work with - let mut t: T = uninitialized(); - - // Perform the swap, `&mut` pointers never alias - ptr::copy_nonoverlapping(&*x, &mut t, 1); - ptr::copy_nonoverlapping(&*y, x, 1); - ptr::copy_nonoverlapping(&t, y, 1); - - // y and t now point to the same thing, but we need to completely - // forget `t` because we do not want to run the destructor for `T` - // on its value, which is still owned somewhere outside this function. - forget(t); - return; - } - // The approach here is to utilize simd to swap x & y efficiently. Testing reveals // that swapping either 32 bytes or 64 bytes at a time is most efficient for intel // Haswell E processors. LLVM is more able to optimize if we give a struct a @@ -534,6 +516,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) { // Loop through x & y, copying them `Block` at a time // The optimizer should unroll the loop fully for most types // N.B. We can't use a for loop as the `range` impl calls `mem::swap` recursively + let len = size_of::<T>(); let mut i = 0; while i + block_size <= len { // Create some uninitialized memory as scratch space |
