Skip to content
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: RegisterHandleCleanups reduce duplication #33421

Closed

Conversation

danbev
Copy link
Contributor

@danbev danbev commented May 15, 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.

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-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 15, 2020
Copy link
Member

@himself65 himself65 left a comment

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

#define V(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

Copy link
Member

@addaleax addaleax left a comment

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
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.

@addaleax addaleax 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
Collaborator

@addaleax
Copy link
Member

Landed in 61189d3

@addaleax addaleax closed this May 19, 2020
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
@codebytere codebytere mentioned this pull request Jun 9, 2020
@codebytere codebytere mentioned this pull request Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs 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