Skip to content

Commit 685a75d

Browse files
committed
Use #[inline(always)] on trivial UnsafeCell methods
UnsafeCell is the standard building block for shared mutable data structures. UnsafeCell should add zero overhead compared to using raw pointers directly. Some reports suggest that debug builds, or even builds at opt-level 1, may not always be inlining its methods. Mark the methods as `#[inline(always)]`, since once inlined the methods should result in no actual code other than field accesses.
1 parent af9862b commit 685a75d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/src/cell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ impl<T> UnsafeCell<T> {
18151815
/// ```
18161816
#[stable(feature = "rust1", since = "1.0.0")]
18171817
#[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
1818-
#[inline]
1818+
#[inline(always)]
18191819
pub const fn new(value: T) -> UnsafeCell<T> {
18201820
UnsafeCell { value }
18211821
}
@@ -1831,7 +1831,7 @@ impl<T> UnsafeCell<T> {
18311831
///
18321832
/// let five = uc.into_inner();
18331833
/// ```
1834-
#[inline]
1834+
#[inline(always)]
18351835
#[stable(feature = "rust1", since = "1.0.0")]
18361836
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
18371837
pub const fn into_inner(self) -> T {
@@ -1856,7 +1856,7 @@ impl<T: ?Sized> UnsafeCell<T> {
18561856
///
18571857
/// let five = uc.get();
18581858
/// ```
1859-
#[inline]
1859+
#[inline(always)]
18601860
#[stable(feature = "rust1", since = "1.0.0")]
18611861
#[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
18621862
pub const fn get(&self) -> *mut T {
@@ -1881,7 +1881,7 @@ impl<T: ?Sized> UnsafeCell<T> {
18811881
///
18821882
/// assert_eq!(*c.get_mut(), 6);
18831883
/// ```
1884-
#[inline]
1884+
#[inline(always)]
18851885
#[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
18861886
pub fn get_mut(&mut self) -> &mut T {
18871887
&mut self.value
@@ -1914,7 +1914,7 @@ impl<T: ?Sized> UnsafeCell<T> {
19141914
///
19151915
/// assert_eq!(uc.into_inner(), 5);
19161916
/// ```
1917-
#[inline]
1917+
#[inline(always)]
19181918
#[unstable(feature = "unsafe_cell_raw_get", issue = "66358")]
19191919
pub const fn raw_get(this: *const Self) -> *mut T {
19201920
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of

0 commit comments

Comments
 (0)