src: prefer OnScopeLeave over shared_ptr<void>

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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
This commit is contained in:
Anna Henningsen
2020-03-13 09:44:53 +01:00
parent f7771fffd0
commit c011542484
2 changed files with 2 additions and 2 deletions

View File

@@ -832,7 +832,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
return;
}
std::shared_ptr<void> 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);

View File

@@ -202,7 +202,7 @@ MaybeLocal<String> NativeModuleLoader::LoadBuiltinModuleSource(Isolate* isolate,
CHECK_GE(req.result, 0);
uv_fs_req_cleanup(&req);
std::shared_ptr<void> 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);