Skip to content

Commit 31bd868

Browse files
committed
Auto merge of rust-lang#85218 - kornelski:pointerinline, r=scottmcm
#[inline(always)] on basic pointer methods Retryng rust-lang#85201 with only inlining pointer methods. The goal is to make pointers behave just like pointers in O0, mainly to reduce overhead in debug builds. cc `@scottmcm`
2 parents 21e92b9 + 3773740 commit 31bd868

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

library/core/src/ptr/mut_ptr.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<T: ?Sized> *mut T {
4242
/// Casts to a pointer of another type.
4343
#[stable(feature = "ptr_cast", since = "1.38.0")]
4444
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
45-
#[inline]
45+
#[inline(always)]
4646
pub const fn cast<U>(self) -> *mut U {
4747
self as _
4848
}
@@ -551,7 +551,7 @@ impl<T: ?Sized> *mut T {
551551
/// ```
552552
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
553553
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
554-
#[inline]
554+
#[inline(always)]
555555
pub const unsafe fn offset_from(self, origin: *const T) -> isize
556556
where
557557
T: Sized,
@@ -859,7 +859,7 @@ impl<T: ?Sized> *mut T {
859859
/// [`ptr::read`]: crate::ptr::read()
860860
#[stable(feature = "pointer_methods", since = "1.26.0")]
861861
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
862-
#[inline]
862+
#[inline(always)]
863863
pub const unsafe fn read(self) -> T
864864
where
865865
T: Sized,
@@ -879,7 +879,7 @@ impl<T: ?Sized> *mut T {
879879
///
880880
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
881881
#[stable(feature = "pointer_methods", since = "1.26.0")]
882-
#[inline]
882+
#[inline(always)]
883883
pub unsafe fn read_volatile(self) -> T
884884
where
885885
T: Sized,
@@ -898,7 +898,7 @@ impl<T: ?Sized> *mut T {
898898
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
899899
#[stable(feature = "pointer_methods", since = "1.26.0")]
900900
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
901-
#[inline]
901+
#[inline(always)]
902902
pub const unsafe fn read_unaligned(self) -> T
903903
where
904904
T: Sized,
@@ -917,7 +917,7 @@ impl<T: ?Sized> *mut T {
917917
/// [`ptr::copy`]: crate::ptr::copy()
918918
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
919919
#[stable(feature = "pointer_methods", since = "1.26.0")]
920-
#[inline]
920+
#[inline(always)]
921921
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
922922
where
923923
T: Sized,
@@ -936,7 +936,7 @@ impl<T: ?Sized> *mut T {
936936
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
937937
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
938938
#[stable(feature = "pointer_methods", since = "1.26.0")]
939-
#[inline]
939+
#[inline(always)]
940940
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
941941
where
942942
T: Sized,
@@ -955,7 +955,7 @@ impl<T: ?Sized> *mut T {
955955
/// [`ptr::copy`]: crate::ptr::copy()
956956
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
957957
#[stable(feature = "pointer_methods", since = "1.26.0")]
958-
#[inline]
958+
#[inline(always)]
959959
pub const unsafe fn copy_from(self, src: *const T, count: usize)
960960
where
961961
T: Sized,
@@ -974,7 +974,7 @@ impl<T: ?Sized> *mut T {
974974
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
975975
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
976976
#[stable(feature = "pointer_methods", since = "1.26.0")]
977-
#[inline]
977+
#[inline(always)]
978978
pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
979979
where
980980
T: Sized,
@@ -989,7 +989,7 @@ impl<T: ?Sized> *mut T {
989989
///
990990
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
991991
#[stable(feature = "pointer_methods", since = "1.26.0")]
992-
#[inline]
992+
#[inline(always)]
993993
pub unsafe fn drop_in_place(self) {
994994
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
995995
unsafe { drop_in_place(self) }
@@ -1003,7 +1003,7 @@ impl<T: ?Sized> *mut T {
10031003
/// [`ptr::write`]: crate::ptr::write()
10041004
#[stable(feature = "pointer_methods", since = "1.26.0")]
10051005
#[rustc_const_unstable(feature = "const_ptr_write", issue = "none")]
1006-
#[inline]
1006+
#[inline(always)]
10071007
pub const unsafe fn write(self, val: T)
10081008
where
10091009
T: Sized,
@@ -1019,7 +1019,7 @@ impl<T: ?Sized> *mut T {
10191019
///
10201020
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
10211021
#[stable(feature = "pointer_methods", since = "1.26.0")]
1022-
#[inline]
1022+
#[inline(always)]
10231023
pub unsafe fn write_bytes(self, val: u8, count: usize)
10241024
where
10251025
T: Sized,
@@ -1039,7 +1039,7 @@ impl<T: ?Sized> *mut T {
10391039
///
10401040
/// [`ptr::write_volatile`]: crate::ptr::write_volatile()
10411041
#[stable(feature = "pointer_methods", since = "1.26.0")]
1042-
#[inline]
1042+
#[inline(always)]
10431043
pub unsafe fn write_volatile(self, val: T)
10441044
where
10451045
T: Sized,
@@ -1058,7 +1058,7 @@ impl<T: ?Sized> *mut T {
10581058
/// [`ptr::write_unaligned`]: crate::ptr::write_unaligned()
10591059
#[stable(feature = "pointer_methods", since = "1.26.0")]
10601060
#[rustc_const_unstable(feature = "const_ptr_write", issue = "none")]
1061-
#[inline]
1061+
#[inline(always)]
10621062
pub const unsafe fn write_unaligned(self, val: T)
10631063
where
10641064
T: Sized,
@@ -1074,7 +1074,7 @@ impl<T: ?Sized> *mut T {
10741074
///
10751075
/// [`ptr::replace`]: crate::ptr::replace()
10761076
#[stable(feature = "pointer_methods", since = "1.26.0")]
1077-
#[inline]
1077+
#[inline(always)]
10781078
pub unsafe fn replace(self, src: T) -> T
10791079
where
10801080
T: Sized,
@@ -1091,7 +1091,7 @@ impl<T: ?Sized> *mut T {
10911091
///
10921092
/// [`ptr::swap`]: crate::ptr::swap()
10931093
#[stable(feature = "pointer_methods", since = "1.26.0")]
1094-
#[inline]
1094+
#[inline(always)]
10951095
pub unsafe fn swap(self, with: *mut T)
10961096
where
10971097
T: Sized,
@@ -1170,7 +1170,7 @@ impl<T> *mut [T] {
11701170
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
11711171
/// assert_eq!(slice.len(), 3);
11721172
/// ```
1173-
#[inline]
1173+
#[inline(always)]
11741174
#[unstable(feature = "slice_ptr_len", issue = "71146")]
11751175
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
11761176
pub const fn len(self) -> usize {
@@ -1190,7 +1190,7 @@ impl<T> *mut [T] {
11901190
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
11911191
/// assert_eq!(slice.as_mut_ptr(), 0 as *mut i8);
11921192
/// ```
1193-
#[inline]
1193+
#[inline(always)]
11941194
#[unstable(feature = "slice_ptr_get", issue = "74265")]
11951195
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
11961196
pub const fn as_mut_ptr(self) -> *mut T {
@@ -1217,7 +1217,7 @@ impl<T> *mut [T] {
12171217
/// }
12181218
/// ```
12191219
#[unstable(feature = "slice_ptr_get", issue = "74265")]
1220-
#[inline]
1220+
#[inline(always)]
12211221
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
12221222
where
12231223
I: SliceIndex<[T]>,
@@ -1332,7 +1332,7 @@ impl<T> *mut [T] {
13321332
// Equality for pointers
13331333
#[stable(feature = "rust1", since = "1.0.0")]
13341334
impl<T: ?Sized> PartialEq for *mut T {
1335-
#[inline]
1335+
#[inline(always)]
13361336
fn eq(&self, other: &*mut T) -> bool {
13371337
*self == *other
13381338
}
@@ -1357,27 +1357,27 @@ impl<T: ?Sized> Ord for *mut T {
13571357

13581358
#[stable(feature = "rust1", since = "1.0.0")]
13591359
impl<T: ?Sized> PartialOrd for *mut T {
1360-
#[inline]
1360+
#[inline(always)]
13611361
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
13621362
Some(self.cmp(other))
13631363
}
13641364

1365-
#[inline]
1365+
#[inline(always)]
13661366
fn lt(&self, other: &*mut T) -> bool {
13671367
*self < *other
13681368
}
13691369

1370-
#[inline]
1370+
#[inline(always)]
13711371
fn le(&self, other: &*mut T) -> bool {
13721372
*self <= *other
13731373
}
13741374

1375-
#[inline]
1375+
#[inline(always)]
13761376
fn gt(&self, other: &*mut T) -> bool {
13771377
*self > *other
13781378
}
13791379

1380-
#[inline]
1380+
#[inline(always)]
13811381
fn ge(&self, other: &*mut T) -> bool {
13821382
*self >= *other
13831383
}

0 commit comments

Comments
 (0)