Skip to content

src: RegisterHandleCleanups reduce duplication - #33421

Closed
danbev wants to merge 1 commit into
nodejs:masterfrom
danbev:register-handle-cleanup-suggestion
Closed

src: RegisterHandleCleanups reduce duplication#33421
danbev wants to merge 1 commit into
nodejs:masterfrom
danbev:register-handle-cleanup-suggestion

Conversation

@danbev

Copy link
Copy Markdown
Contributor

This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.

The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
@nodejs-github-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 15, 2020

@himself65himself65 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using #define macro? I worry about the performance reduce of lambda

#defineV(hook) \
RegisterHandleCleanup( \
reinterpret_cast<uv_handle_t*>(hook), close_and_finish, nullptr)
V(timer_handle());
V(immediate_check_handle());
V(immediate_idle_handle());
V(&idle_prepare_handle_);
V(&idle_check_handle_);
V(&task_queues_async_);
#undef V

@addaleaxaddaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and please, no macro :)

@addaleax

Copy link
Copy Markdown
Member

@himself65 This code is only run once per Environment, so performance is a non-concern, but generally lambdas will perform on par with macros, so they're almost always the better choice.

@addaleaxaddaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 19, 2020
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@addaleax

Copy link
Copy Markdown
Member

Landed in 61189d3

addaleax pushed a commit that referenced this pull request May 19, 2020
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
PR-URL: #33421
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
codebytere pushed a commit that referenced this pull request May 21, 2020
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
PR-URL: #33421
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
codebytere pushed a commit that referenced this pull request Jun 7, 2020
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
PR-URL: #33421
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
codebytere pushed a commit that referenced this pull request Jun 9, 2020
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
PR-URL: #33421
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
@codebyterecodebytere mentioned this pull request Jun 9, 2020
@codebyterecodebytere mentioned this pull request Jun 28, 2020
QwireyInc pushed a commit to QwireyInc/node that referenced this pull request Apr 19, 2025
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.
The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.
PR-URL: nodejs/node#33421
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.c++Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@danbev@addaleax@nodejs-github-bot@jasnell@cjihrig@devnexen@richardlau@himself65