Skip to content

Commit 11e6cc5

Browse files
committed
Swap the encoding used in std::sync::Once
Let the fast path (COMPLETE) to use the constant 0. This may only reduces code sizes by 1 byte on x86/64 but it can reduce an instruction on RISC ISAs.
1 parent b3626a9 commit 11e6cc5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/std/src/sync/once.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ pub const ONCE_INIT: Once = Once::new();
161161

162162
// Four states that a Once can be in, encoded into the lower bits of
163163
// `state_and_queue` in the Once structure.
164-
const INCOMPLETE: usize = 0x0;
164+
const COMPLETE: usize = 0x0;
165165
const POISONED: usize = 0x1;
166166
const RUNNING: usize = 0x2;
167-
const COMPLETE: usize = 0x3;
167+
const INCOMPLETE: usize = 0x3;
168168

169169
// Mask to learn about the state. All other bits are the queue of waiters if
170170
// this is in the RUNNING state.

0 commit comments

Comments
 (0)