This repository was archived by the owner on May 14, 2026. It is now read-only.
Repository navigation
once: add Once::init_from_ref() method - #179
Merged
Merged
Conversation
During the initialization of Once, several operations need to be performed on the internal atomic status to properly get the right to initialize the internal cell. Abstract these operations away into separate methods, in preparation for a new initialization method that will reuse this functionality.
00xc
force-pushed
the
once/init_from_ref
branch
from
December 3, 2025 14:14
295ff90 to
e956fa5
Compare
zesterer
suggested changes
Dec 8, 2025
zesterer
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR. I think this is a good change, and the implementation passes the sniff test. I've just one comment.
Add a method to initialize a Once from a reference to a &T (which implements Copy). This method can be used to avoid expensive copies into the stack in debug builds, which might not be able to optimize away the moving of the value into the internal cell. Add as well a basic test to ensure the functionality is correct.
00xc
force-pushed
the
once/init_from_ref
branch
from
December 8, 2025 22:19
e956fa5 to
267273e
Compare
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
Once::init_from_ref()method, which initializes theOnceonly once by copying from a&T. This is a simpler initialization method that can be used to avoid expensive copies to the stack in debug builds, since the compiler might not be able to optimize away the move of the value into the internal cell.The method has a very simple signature:
To implement this reusing the existing functionality I had to refactor some code out of
try_call_once_slowinto separate methods.