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
Simplify the ReusableObjectHolder #36068
Merged
cmsbuild
merged 6 commits into
cms-sw:master
from
fwyzard:CMSSW_12_2_X_simplify_ReusableObjectHolder
Nov 12, 2021
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d5d8dd
ReusableObjectHolder: remove unused header
fwyzard a902d15
ReusableObjectHolder: reduce code duplication
fwyzard 28cd464
ReusableObjectHolder: do not add new objects to the cache before retu…
fwyzard ca0e6ab
ReusableObjectHolder: check the result of try_pop instead of the valu…
fwyzard 8061379
ReusableObjectHolder: avoid potential copies of the functors
fwyzard 35efc5c
ReusableObjectHolder: update class documentation
fwyzard File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
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.
I believe doing
would avoid a possible copy of the functor.
Possibly an even better solution would be to change the function signature to
makeOrGetAndClear(FM&& iMakeFunc, FC&& iClearFunc)
and then do
A similar function signature change to
makeOrGet
would probably be required to get the most benefit of such a change.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.
Good catch, thanks.
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.
I think this change
should be enough, since
iMakeFunc
is the only one that is copied.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.
At least, my confused understanding is that
FC iClearFunc
(inmakeOrGetAndClear
) andF iFunc
(inmakeOrGet
) should already take any of the functors by reference if they are lvalues.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.
I think using
FC
instead ofFC&&
means the compiler (before optimization) will call the move constructor ofFC
when passed an lvalue. I'd bet that all compilers will remove that call when optimation is turned on. However, usingFC&&
does make the requirements of the arguments more explicit.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.
I was wrong. I tested in godbolt and for the case where the object is created directly in the argument list they are identical.
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.
It does appear that if the argument is created outside of the function argument list, then
FC&&
is the better choice as it does avoid an extra copy.https://godbolt.org/z/7fYG641qq
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.
OK, done - let me know if I missed anything (here or elsewhere).
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.
Sorry, I missed the last comment...
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.
...done, now.