From dc77d4977555430f3dafb8a725ec69751d7a1b9d Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sun, 28 Oct 2018 00:59:04 +0200 Subject: [PATCH] Make a bunch of trivial methods of NonNull be `#[inline]` --- src/libcore/ptr.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index b699cb028842b..0fe82b93ff7a1 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2867,6 +2867,7 @@ impl NonNull { /// sentinel value. Types that lazily allocate must track initialization by /// some other means. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub fn dangling() -> Self { unsafe { let ptr = mem::align_of::() as *mut T; @@ -2882,12 +2883,14 @@ impl NonNull { /// /// `ptr` must be non-null. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { NonNull { pointer: NonZero(ptr as _) } } /// Creates a new `NonNull` if `ptr` is non-null. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub fn new(ptr: *mut T) -> Option { if !ptr.is_null() { Some(NonNull { pointer: NonZero(ptr as _) }) @@ -2898,6 +2901,7 @@ impl NonNull { /// Acquires the underlying `*mut` pointer. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub fn as_ptr(self) -> *mut T { self.pointer.0 as *mut T } @@ -2908,6 +2912,7 @@ impl NonNull { /// it were actually an instance of T that is getting borrowed. If a longer /// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub unsafe fn as_ref(&self) -> &T { &*self.as_ptr() } @@ -2918,12 +2923,14 @@ impl NonNull { /// it were actually an instance of T that is getting borrowed. If a longer /// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`. #[stable(feature = "nonnull", since = "1.25.0")] + #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { &mut *self.as_ptr() } /// Cast to a pointer of another type #[stable(feature = "nonnull_cast", since = "1.27.0")] + #[inline] pub fn cast(self) -> NonNull { unsafe { NonNull::new_unchecked(self.as_ptr() as *mut U) @@ -2963,6 +2970,7 @@ impl Eq for NonNull {} #[stable(feature = "nonnull", since = "1.25.0")] impl PartialEq for NonNull { + #[inline] fn eq(&self, other: &Self) -> bool { self.as_ptr() == other.as_ptr() } @@ -2970,6 +2978,7 @@ impl PartialEq for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl Ord for NonNull { + #[inline] fn cmp(&self, other: &Self) -> Ordering { self.as_ptr().cmp(&other.as_ptr()) } @@ -2977,6 +2986,7 @@ impl Ord for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl PartialOrd for NonNull { + #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.as_ptr().partial_cmp(&other.as_ptr()) } @@ -2984,6 +2994,7 @@ impl PartialOrd for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl hash::Hash for NonNull { + #[inline] fn hash(&self, state: &mut H) { self.as_ptr().hash(state) } @@ -2991,6 +3002,7 @@ impl hash::Hash for NonNull { #[unstable(feature = "ptr_internals", issue = "0")] impl From> for NonNull { + #[inline] fn from(unique: Unique) -> Self { NonNull { pointer: unique.pointer } } @@ -2998,6 +3010,7 @@ impl From> for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl<'a, T: ?Sized> From<&'a mut T> for NonNull { + #[inline] fn from(reference: &'a mut T) -> Self { NonNull { pointer: NonZero(reference as _) } } @@ -3005,6 +3018,7 @@ impl<'a, T: ?Sized> From<&'a mut T> for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl<'a, T: ?Sized> From<&'a T> for NonNull { + #[inline] fn from(reference: &'a T) -> Self { NonNull { pointer: NonZero(reference as _) } }