Skip to content

Commit c2655eb

Browse files
AngelicosPhosphorosscottmcm
authored andcommitted
Tweak the threshold for chunked swapping
Thanks to 98892 for the tests I brought in here, as it demonstrated that 3×usize is currently suboptimal.
1 parent 60727ce commit c2655eb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/mem/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ pub const fn swap<T>(x: &mut T, y: &mut T) {
736736
// tends to copy the whole thing to stack rather than doing it one part
737737
// at a time, so instead treat them as one-element slices and piggy-back
738738
// the slice optimizations that will split up the swaps.
739-
if size_of::<T>() / align_of::<T>() > 4 {
739+
if const { size_of::<T>() / align_of::<T>() > 2 } {
740740
// SAFETY: exclusive references always point to one non-overlapping
741741
// element and are non-null and properly aligned.
742742
return unsafe { ptr::swap_nonoverlapping(x, y, 1) };

0 commit comments

Comments
 (0)