-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Simplify the ReusableObjectHolder #36068
Conversation
please test |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36068/26537
|
A new Pull Request was created by @fwyzard (Andrea Bocci) for master. It involves the following packages:
@makortel, @smuzaffar, @Dr15Jones can you please review it and eventually sign? Thanks. cms-bot commands are listed here |
+1 Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-197053/20423/summary.html Comparison SummarySummary:
|
By the way, @Dr15Jones @makortel, I think the example for the
which seems to imply that template< typename FM, typename FC>
std::shared_ptr<T> makeOrGetAndClear( FM iMakeFunc, FC iClearFunc) {
std::shared_ptr<T> returnValue;
while ( ! ( returnValue = tryToGet()) ) {
add( std::unique_ptr<T>(iMakeFunc()) );
}
iClearFunc(returnValue.get());
return returnValue;
} I think that If you confirm that this is desired behaviour (hopefully simplified but unchanged by this PR) I can update the comments as well. |
while (!(returnValue = tryToGet())) { | ||
add(makeUnique(iMakeFunc())); | ||
} | ||
std::shared_ptr<T> returnValue = makeOrGet(iMakeFunc); |
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
std::shared_ptr<T> returnValue = makeOrGet(iMakeFunc); | |
std::shared_ptr<T> returnValue = makeOrGet(std::move(iMakeFunc)); |
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
std::shared_ptr<T> returnValue = makeOrGet(iMakeFunc); | |
std::shared_ptr<T> returnValue = makeOrGet(std::forward<FM>(iMakeFunc)); |
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
template <typename FM, typename FC>
std::shared_ptr<T> makeOrGetAndClear(FM&& iMakeFunc, FC iClearFunc) {
std::shared_ptr<T> returnValue = makeOrGet(std::forward<FM>(iMakeFunc));
iClearFunc(returnValue.get());
return returnValue;
}
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
(in makeOrGetAndClear
) and F iFunc
(in makeOrGet
) 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 of FC&&
means the compiler (before optimization) will call the move constructor of FC
when passed an lvalue. I'd bet that all compilers will remove that call when optimation is turned on. However, using FC&&
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.
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.
please test |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36068/26575
|
The unit test seem to agree that cmssw/FWCore/Utilities/test/reusableobjectholder_t.cppunit.cpp Lines 67 to 75 in c272d72
So, I'm not sure how
is better than
? It doesn't seem to be used anywhere in CMSSW. On the other hand, it doesn't add any complexity or cost. I'll update the comments, though. |
please test |
+code-checks Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-36068/26592
|
Pull request #36068 was updated. @makortel, @smuzaffar, @Dr15Jones can you please check and sign again. |
+1 Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-197053/20486/summary.html Comparison SummarySummary:
|
+1 |
This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @perrotta, @dpiparo, @qliphy (and backports should be raised in the release meeting by the corresponding L2) |
+1 |
PR description:
Simplify the
ReusableObjectHolder
:PR validation:
Unit tests pass.