-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Leverage &mut in OnceLock when possible #149469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
| debug_assert!(self.is_initialized()); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already checked in get_unchecked
| if self.get_mut().is_none() { | ||
| self.initialize(f)?; | ||
| } | ||
| debug_assert!(self.is_initialized()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already checked in get_unchecked_mut
|
|
||
| #[inline] | ||
| fn is_initialized(&self) -> bool { | ||
| fn initialized(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aligned with initialized_mut.
is_initialized_mut doesn't follow some idioms that is_xxx would typically take &self.
Signed-off-by: tison <wander4096@gmail.com>
| fn initialized_mut(&mut self) -> bool { | ||
| // `state()` does not perform an atomic load, so prefer it over `is_complete()`. | ||
| let state = self.once.state(); | ||
| match state { | ||
| OnceExclusiveState::Complete => true, | ||
| _ => false, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what LazyLock already does.
See comments inline.