Skip to content

Commit

Permalink
Rollup merge of rust-lang#123356 - joboet:set_current_size, r=ChrisDe…
Browse files Browse the repository at this point in the history
…nton

Reduce code size of `thread::set_current`

rust-lang#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
  • Loading branch information
matthiaskrgr authored May 4, 2024
2 parents 2c4bf24 + 37c1758 commit d596b1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,14 @@ thread_local! {

/// Sets the thread handle for the current thread.
///
/// Panics if the handle has been set already or when called from a TLS destructor.
/// Aborts if the handle has been set already to reduce code size.
pub(crate) fn set_current(thread: Thread) {
CURRENT.with(|current| current.set(thread).unwrap());
// Using `unwrap` here can add ~3kB to the binary size. We have complete
// control over where this is called, so just abort if there is a bug.
CURRENT.with(|current| match current.set(thread) {
Ok(()) => {}
Err(_) => rtabort!("thread::set_current should only be called once per thread"),
});
}

/// Gets a handle to the thread that invokes it.
Expand Down

0 comments on commit d596b1e

Please sign in to comment.