Skip to content

Commit 5439198

Browse files
committed
Use non-overlapping swap for inner heapsort loop
This regresses binary-size slightly for normal builds, but the important release_lto_thin_opt_level_s config sees a small improvement in binary-size and a larger types such as string and 1k see 2-3% run-time improvements with this change.
1 parent a0e4303 commit 5439198

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

library/core/src/slice/sort/unstable/heapsort.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ where
6969
break;
7070
}
7171

72-
// Swap `node` with the greater child, move one step down, and continue sifting. This
73-
// could be ptr::swap_nonoverlapping but that adds a significant amount of binary-size.
74-
ptr::swap(v_base.add(node), v_base.add(child));
72+
ptr::swap_nonoverlapping(v_base.add(node), v_base.add(child), 1);
7573
}
7674

7775
node = child;

0 commit comments

Comments
 (0)