Skip to content

Commit

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

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
bors committed Apr 3, 2024
2 parents ceab612 + 061d873 commit 62bf84c
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 @@ -684,9 +684,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!("should only be set once"),
});
}

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

0 comments on commit 62bf84c

Please sign in to comment.