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
src: prevent extra copies of TimerWrap::TimerCb
#40665
Merged
nodejs-github-bot
merged 1 commit into
nodejs:master
from
RaisinTen:src/prevent-extra-copies-of-TimerWrap-TimerCb
Nov 12, 2021
Merged
src: prevent extra copies of TimerWrap::TimerCb
#40665
nodejs-github-bot
merged 1 commit into
nodejs:master
from
RaisinTen:src/prevent-extra-copies-of-TimerWrap-TimerCb
Nov 12, 2021
Conversation
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
This comment has been hidden.
This comment has been hidden.
34 tasks
This comment has been hidden.
This comment has been hidden.
addaleax
approved these changes
Oct 31, 2021
38 tasks
35 tasks
JungMinu
approved these changes
Nov 2, 2021
I noticed that we were taking `TimerCb` as a `const&` and then copying that into the member. This is completely fine when the constructor is called with an lvalue. However, when called with an rvalue, we can allow the `std::function` to be moved into the member instead of falling back to a copy, so I changed the constructors to take in universal references. Also, `std::function` constructors can take in multiple arguments, so I further modified the constructors to use variadic templates. Signed-off-by: Darshan Sen <darshan.sen@postman.com>
6047d0a
to
bc7efeb
This comment has been hidden.
This comment has been hidden.
42 tasks
This comment has been hidden.
This comment has been hidden.
44 tasks
43 tasks
44 tasks
46 tasks
|
I had to rebase on top of #40684 to fix the flaky tests. Can this get another review plz? |
Commit Queue failed- Loading data for nodejs/node/pull/40665 ✔ Done loading data for nodejs/node/pull/40665 ----------------------------------- PR info ------------------------------------ Title src: prevent extra copies of `TimerWrap::TimerCb` (#40665) Author Darshan Sen (@RaisinTen) Branch RaisinTen:src/prevent-extra-copies-of-TimerWrap-TimerCb -> nodejs:master Labels c++, lib / src, author ready Commits 1 - src: prevent extra copies of `TimerWrap::TimerCb` Committers 1 - Darshan Sen PR-URL: https://github.com/nodejs/node/pull/40665 Reviewed-By: Anna Henningsen Reviewed-By: Minwoo Jung ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/40665 Reviewed-By: Anna Henningsen Reviewed-By: Minwoo Jung -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - src: prevent extra copies of `TimerWrap::TimerCb` ℹ This PR was created on Sat, 30 Oct 2021 15:56:09 GMT ✔ Approvals: 2 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/40665#pullrequestreview-793747833 ✔ - Minwoo Jung (@JungMinu): https://github.com/nodejs/node/pull/40665#pullrequestreview-794777797 ✔ Last GitHub Actions successful ℹ Last Full PR CI on 2021-11-03T13:44:37Z: https://ci.nodejs.org/job/node-test-pull-request/40683/ - Querying data for job/node-test-pull-request/40683/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/1431079248 |
46 tasks
|
Landed in 2d368da |
targos
added a commit
that referenced
this issue
Nov 21, 2021
I noticed that we were taking `TimerCb` as a `const&` and then copying that into the member. This is completely fine when the constructor is called with an lvalue. However, when called with an rvalue, we can allow the `std::function` to be moved into the member instead of falling back to a copy, so I changed the constructors to take in universal references. Also, `std::function` constructors can take in multiple arguments, so I further modified the constructors to use variadic templates. Signed-off-by: Darshan Sen <darshan.sen@postman.com> PR-URL: #40665 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I noticed that we were taking
TimerCbas aconst&and then copyingthat into the member. This is completely fine when the constructor is
called with an lvalue. However, when called with an rvalue, we can allow
the
std::functionto be moved into the member instead of falling backto a copy, so I changed the constructors to take in universal
references. Also,
std::functionconstructors can take in multiplearguments, so I further modified the constructors to use variadic
templates.
Signed-off-by: Darshan Sen darshan.sen@postman.com
The text was updated successfully, but these errors were encountered: