Skip to content

Commit

Permalink
Use inline(never) instead of cold
Browse files Browse the repository at this point in the history
inline(never) is better way to avoid optimizer to inline the function instead of cold.
  • Loading branch information
howard0su authored Sep 2, 2020
1 parent 80fc9b0 commit a80d390
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,9 @@ pub mod fast {
// thread_local's, or it is being recursively initialized.
//
// Macos: Inlining this function can cause two `tlv_get_addr` calls to
// be performed for every call to `Key::get`. The #[cold] hint makes
// that less likely.
// be performed for every call to `Key::get`.
// LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722
#[cold]
#[inline(never)]
unsafe fn try_initialize<F: FnOnce() -> T>(&self, init: F) -> Option<&'static T> {
if !mem::needs_drop::<T>() || self.try_register_dtor() {
Some(self.inner.initialize(init))
Expand Down

0 comments on commit a80d390

Please sign in to comment.