From 61189d3981ef49885f8d98eef2ac0207b6e59f40 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 15 May 2020 14:11:34 +0200 Subject: [PATCH] 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 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Zeyu Yang Reviewed-By: David Carlier --- src/env.cc | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/env.cc b/src/env.cc index feb648a2b66aaf..39e0d7309ef92f 100644 --- a/src/env.cc +++ b/src/env.cc @@ -567,30 +567,15 @@ void Environment::RegisterHandleCleanups() { }); }; - RegisterHandleCleanup( - reinterpret_cast(timer_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast(immediate_check_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast(immediate_idle_handle()), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast(&idle_prepare_handle_), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast(&idle_check_handle_), - close_and_finish, - nullptr); - RegisterHandleCleanup( - reinterpret_cast(&task_queues_async_), - close_and_finish, - nullptr); + auto register_handle = [&](uv_handle_t* handle) { + RegisterHandleCleanup(handle, close_and_finish, nullptr); + }; + register_handle(reinterpret_cast(timer_handle())); + register_handle(reinterpret_cast(immediate_check_handle())); + register_handle(reinterpret_cast(immediate_idle_handle())); + register_handle(reinterpret_cast(&idle_prepare_handle_)); + register_handle(reinterpret_cast(&idle_check_handle_)); + register_handle(reinterpret_cast(&task_queues_async_)); } void Environment::CleanupHandles() {