Skip to content

Commit 5ba5865

Browse files
committed
swap_ptr: rm equality check
This isn't needed semantically, and it's the wrong case to optimize for.
1 parent 6e2b082 commit 5ba5865

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/libstd/ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
103103
let n = count * sys::size_of::<T>();
104104
memmove32(dst as *mut u8, src as *u8, n as u32);
105105
}
106+
106107
#[inline(always)]
107108
#[cfg(target_word_size = "64")]
108109
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {

src/libstd/util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
6161
*/
6262
#[inline]
6363
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
64-
if x == y { return }
65-
6664
// Give ourselves some scratch space to work with
6765
let mut tmp: T = intrinsics::uninit();
6866
let t = ptr::to_mut_unsafe_ptr(&mut tmp);
@@ -72,7 +70,7 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
7270
ptr::copy_memory(x, y, 1);
7371
ptr::copy_memory(y, t, 1);
7472

75-
// y and t now point to the same thing, but we need to completely forget t
73+
// y and t now point to the same thing, but we need to completely forget `tmp`
7674
// because it's no longer relevant.
7775
cast::forget(tmp);
7876
}

0 commit comments

Comments
 (0)