From 59786b020be2fa72829158fb02c58da537b294ee Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 20 Nov 2018 23:37:02 +0100 Subject: [PATCH] use more inlining, and force some of it --- src/libcore/mem.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 56ba10c49f4..a5603ff6a62 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -950,7 +950,7 @@ impl ManuallyDrop { /// ManuallyDrop::new(Box::new(())); /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] - #[inline] + #[inline(always)] pub const fn new(value: T) -> ManuallyDrop { ManuallyDrop { value } } @@ -967,7 +967,7 @@ pub const fn new(value: T) -> ManuallyDrop { /// let _: Box<()> = ManuallyDrop::into_inner(x); // This drops the `Box`. /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] - #[inline] + #[inline(always)] pub const fn into_inner(slot: ManuallyDrop) -> T { slot.value } @@ -1015,7 +1015,7 @@ pub unsafe fn drop(slot: &mut ManuallyDrop) { #[stable(feature = "manually_drop", since = "1.20.0")] impl Deref for ManuallyDrop { type Target = T; - #[inline] + #[inline(always)] fn deref(&self) -> &T { &self.value } @@ -1023,7 +1023,7 @@ fn deref(&self) -> &T { #[stable(feature = "manually_drop", since = "1.20.0")] impl DerefMut for ManuallyDrop { - #[inline] + #[inline(always)] fn deref_mut(&mut self) -> &mut T { &mut self.value } @@ -1044,6 +1044,7 @@ impl MaybeUninit { /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub const fn new(val: T) -> MaybeUninit { MaybeUninit { value: ManuallyDrop::new(val) } } @@ -1053,6 +1054,7 @@ pub const fn new(val: T) -> MaybeUninit { /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub const fn uninitialized() -> MaybeUninit { MaybeUninit { uninit: () } } @@ -1066,6 +1068,7 @@ pub const fn uninitialized() -> MaybeUninit { /// Note that dropping a `MaybeUninit` will never call `T`'s drop code. /// It is your responsibility to make sure `T` gets dropped if it got initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline] pub fn zeroed() -> MaybeUninit { let mut u = MaybeUninit::::uninitialized(); unsafe { @@ -1076,6 +1079,7 @@ pub fn zeroed() -> MaybeUninit { /// Set the value of the `MaybeUninit`. This overwrites any previous value without dropping it. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub fn set(&mut self, val: T) { unsafe { self.value = ManuallyDrop::new(val); @@ -1091,6 +1095,7 @@ pub fn set(&mut self, val: T) { /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state, otherwise this will immediately cause undefined behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub unsafe fn into_inner(self) -> T { ManuallyDrop::into_inner(self.value) } @@ -1102,6 +1107,7 @@ pub unsafe fn into_inner(self) -> T { /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state, otherwise this will immediately cause undefined behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub unsafe fn get_ref(&self) -> &T { &*self.value } @@ -1113,6 +1119,7 @@ pub unsafe fn get_ref(&self) -> &T { /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized /// state, otherwise this will immediately cause undefined behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub unsafe fn get_mut(&mut self) -> &mut T { &mut *self.value } @@ -1120,6 +1127,7 @@ pub unsafe fn get_mut(&mut self) -> &mut T { /// Get a pointer to the contained value. Reading from this pointer will be undefined /// behavior unless the `MaybeUninit` is initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub fn as_ptr(&self) -> *const T { unsafe { &*self.value as *const T } } @@ -1127,6 +1135,7 @@ pub fn as_ptr(&self) -> *const T { /// Get a mutable pointer to the contained value. Reading from this pointer will be undefined /// behavior unless the `MaybeUninit` is initialized. #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] pub fn as_mut_ptr(&mut self) -> *mut T { unsafe { &mut *self.value as *mut T } }