Skip to content

Commit

Permalink
src: prefer OnScopeLeave over shared_ptr<void>
Browse files Browse the repository at this point in the history
They do the same thing, but OnScopeLeave avoids an extra
heap allocation and is more explicit about what it does.

PR-URL: #32247
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Mar 24, 2020
1 parent 569e555 commit f873d87
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,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);
Expand Down
2 changes: 1 addition & 1 deletion src/node_native_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f873d87

Please sign in to comment.