@@ -473,19 +473,21 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
473
473
#[ inline]
474
474
#[ rustc_const_unstable( feature = "const_swap" , issue = "83163" ) ]
475
475
pub ( crate ) const unsafe fn swap_nonoverlapping_one < T > ( x : * mut T , y : * mut T ) {
476
- // For types smaller than the block optimization below,
477
- // just swap directly to avoid pessimizing codegen.
478
- if mem:: size_of :: < T > ( ) < 32 {
479
- // SAFETY: the caller must guarantee that `x` and `y` are valid
480
- // for writes, properly aligned, and non-overlapping.
481
- unsafe {
482
- let z = read ( x) ;
483
- copy_nonoverlapping ( y, x, 1 ) ;
484
- write ( y, z) ;
485
- }
486
- } else {
476
+ // Only apply the block optimization in `swap_nonoverlapping_bytes` for types
477
+ // at least as large as the block size, to avoid pessimizing codegen.
478
+ if mem:: size_of :: < T > ( ) >= 32 {
487
479
// SAFETY: the caller must uphold the safety contract for `swap_nonoverlapping`.
488
480
unsafe { swap_nonoverlapping ( x, y, 1 ) } ;
481
+ return ;
482
+ }
483
+
484
+ // Direct swapping, for the cases not going through the block optimization.
485
+ // SAFETY: the caller must guarantee that `x` and `y` are valid
486
+ // for writes, properly aligned, and non-overlapping.
487
+ unsafe {
488
+ let z = read ( x) ;
489
+ copy_nonoverlapping ( y, x, 1 ) ;
490
+ write ( y, z) ;
489
491
}
490
492
}
491
493
0 commit comments