about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-05 06:21:14 +0000
committerbors <bors@rust-lang.org>2021-04-05 06:21:14 +0000
commit58e71896506edb701f276158bd2f47e8788a1133 (patch)
tree9cde6ac1b3496550920bbe9d32b98371be862e0f
parentb1b0a1597c40b55b81e5b95ea5fc825a1287b2bb (diff)
parent37498a19dedb4105f8800a7cc2473803fd4bbccf (diff)
downloadrust-58e71896506edb701f276158bd2f47e8788a1133.tar.gz
rust-58e71896506edb701f276158bd2f47e8788a1133.zip
Auto merge of #83858 - joshtriplett:unsafe-cell-always-inline, r=Mark-Simulacrum
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.
-rw-r--r--library/core/src/cell.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs
index 9a2908c275d..4820588df25 100644
--- a/library/core/src/cell.rs
+++ b/library/core/src/cell.rs
@@ -1815,7 +1815,7 @@ impl<T> UnsafeCell<T> {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
-    #[inline]
+    #[inline(always)]
     pub const fn new(value: T) -> UnsafeCell<T> {
         UnsafeCell { value }
     }
@@ -1831,7 +1831,7 @@ impl<T> UnsafeCell<T> {
     ///
     /// let five = uc.into_inner();
     /// ```
-    #[inline]
+    #[inline(always)]
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
     pub const fn into_inner(self) -> T {
@@ -1856,7 +1856,7 @@ impl<T: ?Sized> UnsafeCell<T> {
     ///
     /// let five = uc.get();
     /// ```
-    #[inline]
+    #[inline(always)]
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
     pub const fn get(&self) -> *mut T {
@@ -1881,7 +1881,7 @@ impl<T: ?Sized> UnsafeCell<T> {
     ///
     /// assert_eq!(*c.get_mut(), 6);
     /// ```
-    #[inline]
+    #[inline(always)]
     #[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
     pub fn get_mut(&mut self) -> &mut T {
         &mut self.value
@@ -1914,7 +1914,7 @@ impl<T: ?Sized> UnsafeCell<T> {
     ///
     /// assert_eq!(uc.into_inner(), 5);
     /// ```
-    #[inline]
+    #[inline(always)]
     #[unstable(feature = "unsafe_cell_raw_get", issue = "66358")]
     pub const fn raw_get(this: *const Self) -> *mut T {
         // We can just cast the pointer from `UnsafeCell<T>` to `T` because of