diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2020-05-15 15:11:34 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-05-20 00:56:16 +0300 |
commit | 61189d3981ef49885f8d98eef2ac0207b6e59f40 (patch) | |
tree | ed4c1f9ed449e7092057583b8b645c610ce2c92e | |
parent | 7c755b06cee4cf3c3e3841fb891670122f50ee24 (diff) |
src: reduce duplication in RegisterHandleCleanups
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: https://github.com/nodejs/node/pull/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>
-rw-r--r-- | src/env.cc | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/env.cc b/src/env.cc index feb648a2b66..39e0d7309ef 100644 --- a/src/env.cc +++ b/src/env.cc @@ -567,30 +567,15 @@ void Environment::RegisterHandleCleanups() { }); }; - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(timer_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(immediate_check_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(immediate_idle_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(&idle_check_handle_), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast<uv_handle_t*>(&task_queues_async_), - close_and_finish, - nullptr); + auto register_handle = [&](uv_handle_t* handle) { + RegisterHandleCleanup(handle, close_and_finish, nullptr); + }; + register_handle(reinterpret_cast<uv_handle_t*>(timer_handle())); + register_handle(reinterpret_cast<uv_handle_t*>(immediate_check_handle())); + register_handle(reinterpret_cast<uv_handle_t*>(immediate_idle_handle())); + register_handle(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); + register_handle(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); + register_handle(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); } void Environment::CleanupHandles() { |