about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEduardo Sánchez Muñoz <esm@eduardosm.net>2020-06-24 18:17:27 +0200
committerEduardo Sánchez Muñoz <esm@eduardosm.net>2020-06-24 18:17:27 +0200
commit771a1d8e0ad4e6702aaab91cb5e58adbf3ec3708 (patch)
treef0c9494c862b6c86f6ee0b0c4d59018886a3d853 /src/libstd
parentf03cf9916a1932f47b788a9de9256269cc172fe9 (diff)
downloadrust-771a1d8e0ad4e6702aaab91cb5e58adbf3ec3708.tar.gz
rust-771a1d8e0ad4e6702aaab91cb5e58adbf3ec3708.zip
Make `std::panicking::panic_count::is_zero` inline and move the slow path into a separate cold function.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/panicking.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index 46196960e71..9a5d5e2b5ae 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -258,6 +258,7 @@ pub mod panic_count {
         LOCAL_PANIC_COUNT.with(|c| c.get())
     }
 
+    #[inline]
     pub fn is_zero() -> bool {
         if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) == 0 {
             // Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads
@@ -265,9 +266,17 @@ pub mod panic_count {
             // equal to zero, so TLS access can be avoided.
             true
         } else {
-            LOCAL_PANIC_COUNT.with(|c| c.get() == 0)
+            is_zero_slow_path()
         }
     }
+
+    // Slow path is in a separate function to reduce the amount of code
+    // inlined from `is_zero`.
+    #[inline(never)]
+    #[cold]
+    fn is_zero_slow_path() -> bool {
+        LOCAL_PANIC_COUNT.with(|c| c.get() == 0)
+    }
 }
 
 #[cfg(test)]
@@ -350,6 +359,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
 }
 
 /// Determines whether the current thread is unwinding because of panic.
+#[inline]
 pub fn panicking() -> bool {
     !panic_count::is_zero()
 }