From 43e9ae8317e7c7e9bd991840820df588b485a1d6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 13 Mar 2020 09:44:53 +0100 Subject: [PATCH] src: prefer OnScopeLeave over shared_ptr They do the same thing, but OnScopeLeave avoids an extra heap allocation and is more explicit about what it does. PR-URL: https://github.com/nodejs/node/pull/32247 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Matheus Marchini --- src/node_file.cc | 2 +- src/node_native_module.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 259df8256f2e08..bebb3a87564e3e 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -821,7 +821,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo& args) { return; } - std::shared_ptr defer_close(nullptr, [fd, loop] (...) { + auto defer_close = OnScopeLeave([fd, loop]() { uv_fs_t close_req; CHECK_EQ(0, uv_fs_close(loop, &close_req, fd, nullptr)); uv_fs_req_cleanup(&close_req); diff --git a/src/node_native_module.cc b/src/node_native_module.cc index 680c585d0fb3df..1b916d645d8639 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -202,7 +202,7 @@ MaybeLocal NativeModuleLoader::LoadBuiltinModuleSource(Isolate* isolate, CHECK_GE(req.result, 0); uv_fs_req_cleanup(&req); - std::shared_ptr defer_close(nullptr, [file](...) { + auto defer_close = OnScopeLeave([file]() { uv_fs_t close_req; CHECK_EQ(0, uv_fs_close(nullptr, &close_req, file, nullptr)); uv_fs_req_cleanup(&close_req);