Skip to content

Commit f6227c0

Browse files
danbevtargos
authored andcommitted
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: #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]>
1 parent 85ce30f commit f6227c0

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/env.cc

+9-24
Original file line numberDiff line numberDiff line change
@@ -567,30 +567,15 @@ void Environment::RegisterHandleCleanups() {
567567
});
568568
};
569569

570-
RegisterHandleCleanup(
571-
reinterpret_cast<uv_handle_t*>(timer_handle()),
572-
close_and_finish,
573-
nullptr);
574-
RegisterHandleCleanup(
575-
reinterpret_cast<uv_handle_t*>(immediate_check_handle()),
576-
close_and_finish,
577-
nullptr);
578-
RegisterHandleCleanup(
579-
reinterpret_cast<uv_handle_t*>(immediate_idle_handle()),
580-
close_and_finish,
581-
nullptr);
582-
RegisterHandleCleanup(
583-
reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_),
584-
close_and_finish,
585-
nullptr);
586-
RegisterHandleCleanup(
587-
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
588-
close_and_finish,
589-
nullptr);
590-
RegisterHandleCleanup(
591-
reinterpret_cast<uv_handle_t*>(&task_queues_async_),
592-
close_and_finish,
593-
nullptr);
570+
auto register_handle = [&](uv_handle_t* handle) {
571+
RegisterHandleCleanup(handle, close_and_finish, nullptr);
572+
};
573+
register_handle(reinterpret_cast<uv_handle_t*>(timer_handle()));
574+
register_handle(reinterpret_cast<uv_handle_t*>(immediate_check_handle()));
575+
register_handle(reinterpret_cast<uv_handle_t*>(immediate_idle_handle()));
576+
register_handle(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
577+
register_handle(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
578+
register_handle(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
594579
}
595580

596581
void Environment::CleanupHandles() {

0 commit comments

Comments
 (0)