Skip to content

Commit c00eb4b

Browse files
committed
Auto merge of rust-lang#111803 - scottmcm:simple-swap-alternative, r=Mark-Simulacrum
Tweak the threshold for chunked swapping Thanks to `@AngelicosPhosphoros` for the tests here, which I copied from rust-lang#98892. This is an experiment as a simple alternative to that PR that just tweaks the existing threshold, since that PR showed that 3×Align (like `String`) currently doesn't work as well as it could.
2 parents ef34f56 + 2868c19 commit c00eb4b

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)