From 4b9914a318d8403c8557d069116f417bac61544a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 8 Mar 2018 13:56:31 +0100 Subject: [PATCH] src: avoid duplicate Before/AtExitCallback structs Currently, BeforeExitCallback and AtExitCallback are identical apart for the name of the struct. This commit introduces an ExitCallback struct with can be used in both cases to avoid the duplication. PR-URL: https://github.com/nodejs/node/pull/19226 Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/env.cc | 8 ++++---- src/env.h | 10 +++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/env.cc b/src/env.cc index 455f5980731f3f..960cc4d5f88a69 100644 --- a/src/env.cc +++ b/src/env.cc @@ -218,25 +218,25 @@ void Environment::PrintSyncTrace() const { } void Environment::RunBeforeExitCallbacks() { - for (BeforeExitCallback before_exit : before_exit_functions_) { + for (ExitCallback before_exit : before_exit_functions_) { before_exit.cb_(before_exit.arg_); } before_exit_functions_.clear(); } void Environment::BeforeExit(void (*cb)(void* arg), void* arg) { - before_exit_functions_.push_back(BeforeExitCallback{cb, arg}); + before_exit_functions_.push_back(ExitCallback{cb, arg}); } void Environment::RunAtExitCallbacks() { - for (AtExitCallback at_exit : at_exit_functions_) { + for (ExitCallback at_exit : at_exit_functions_) { at_exit.cb_(at_exit.arg_); } at_exit_functions_.clear(); } void Environment::AtExit(void (*cb)(void* arg), void* arg) { - at_exit_functions_.push_back(AtExitCallback{cb, arg}); + at_exit_functions_.push_back(ExitCallback{cb, arg}); } void Environment::AddPromiseHook(promise_hook_func fn, void* arg) { diff --git a/src/env.h b/src/env.h index dcabf7f54fadef..dc51858dbc0ef9 100644 --- a/src/env.h +++ b/src/env.h @@ -799,17 +799,13 @@ class Environment { double* fs_stats_field_array_; - struct BeforeExitCallback { + struct ExitCallback { void (*cb_)(void* arg); void* arg_; }; - std::list before_exit_functions_; + std::list before_exit_functions_; - struct AtExitCallback { - void (*cb_)(void* arg); - void* arg_; - }; - std::list at_exit_functions_; + std::list at_exit_functions_; struct PromiseHookCallback { promise_hook_func cb_;