Skip to content

Commit 5292020

Browse files
committed
Make mem::swap inlinable
1 parent 5ce39f4 commit 5292020

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/core/src/mem/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ pub const fn swap<T>(x: &mut T, y: &mut T) {
732732
// tends to copy the whole thing to stack rather than doing it one part
733733
// at a time, so instead treat them as one-element slices and piggy-back
734734
// the slice optimizations that will split up the swaps.
735-
if size_of::<T>() / align_of::<T>() > 4 {
735+
if T::IS_BIG_SWAP {
736736
// SAFETY: exclusive references always point to one non-overlapping
737737
// element and are non-null and properly aligned.
738738
return unsafe { ptr::swap_nonoverlapping(x, y, 1) };
@@ -1273,3 +1273,9 @@ pub trait SizedTypeProperties: Sized {
12731273
#[doc(hidden)]
12741274
#[unstable(feature = "sized_type_properties", issue = "none")]
12751275
impl<T> SizedTypeProperties for T {}
1276+
1277+
trait InternalSizedTypeProperties: Sized {
1278+
const IS_BIG_SWAP: bool = size_of::<Self>() / align_of::<Self>() > 4;
1279+
}
1280+
1281+
impl<T> InternalSizedTypeProperties for T {}

0 commit comments

Comments
 (0)