From 5292020971549e2924fb0f32734571114528fe94 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 20 Jan 2023 19:06:50 -0500 Subject: [PATCH] Make mem::swap inlinable --- library/core/src/mem/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 5e01ccc07d8fd..cf70c7999aebe 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -732,7 +732,7 @@ pub const fn swap(x: &mut T, y: &mut T) { // tends to copy the whole thing to stack rather than doing it one part // at a time, so instead treat them as one-element slices and piggy-back // the slice optimizations that will split up the swaps. - if size_of::() / align_of::() > 4 { + if T::IS_BIG_SWAP { // SAFETY: exclusive references always point to one non-overlapping // element and are non-null and properly aligned. return unsafe { ptr::swap_nonoverlapping(x, y, 1) }; @@ -1273,3 +1273,9 @@ pub trait SizedTypeProperties: Sized { #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] impl SizedTypeProperties for T {} + +trait InternalSizedTypeProperties: Sized { + const IS_BIG_SWAP: bool = size_of::() / align_of::() > 4; +} + +impl InternalSizedTypeProperties for T {}