From 1462500b5288159c681272f4adb75debee5bd58b 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. --- 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 8cc060130f7380..f52df35e8d3e0f 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -832,7 +832,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);