Skip to content

Commit 69dac4b

Browse files
addaleaxMylesBorins
authored andcommitted
src: do not use std::function for OnScopeLeave
Using `std::function` adds an extra layer of indirection, and in particular, heap allocations that are not necessary in our use case here. PR-URL: #30134 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f080239 commit 69dac4b

11 files changed

+44
-21
lines changed

src/api/callback.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void InternalCallbackScope::Close() {
105105

106106
if (!env_->can_call_into_js()) return;
107107

108-
OnScopeLeave weakref_cleanup([&]() { env_->RunWeakRefCleanup(); });
108+
auto weakref_cleanup = OnScopeLeave([&]() { env_->RunWeakRefCleanup(); });
109109

110110
if (!tick_info->has_tick_scheduled()) {
111111
MicrotasksScope::PerformCheckpoint(env_->isolate());

src/node_binding.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void* wrapped_dlopen(const char* filename, int flags) {
153153
Mutex::ScopedLock lock(dlhandles_mutex);
154154

155155
uv_fs_t req;
156-
OnScopeLeave cleanup([&]() { uv_fs_req_cleanup(&req); });
156+
auto cleanup = OnScopeLeave([&]() { uv_fs_req_cleanup(&req); });
157157
int rc = uv_fs_stat(nullptr, &req, filename, nullptr);
158158

159159
if (rc != 0) {

src/node_env_var.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Local<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
132132
uv_env_item_t* items;
133133
int count;
134134

135-
OnScopeLeave cleanup([&]() { uv_os_free_environ(items, count); });
135+
auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); });
136136
CHECK_EQ(uv_os_environ(&items, &count), 0);
137137

138138
MaybeStackBuffer<Local<Value>, 256> env_v(count);

src/node_http_parser_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ class Parser : public AsyncWrap, public StreamListener {
606606
// Once we’re done here, either indicate that the HTTP parser buffer
607607
// is free for re-use, or free() the data if it didn’t come from there
608608
// in the first place.
609-
OnScopeLeave on_scope_leave([&]() {
609+
auto on_scope_leave = OnScopeLeave([&]() {
610610
if (buf.base == env()->http_parser_buffer())
611611
env()->set_http_parser_buffer_in_use(false);
612612
else

src/node_i18n.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ConverterObject : public BaseObject, Converter {
217217
result.AllocateSufficientStorage(limit);
218218

219219
UBool flush = (flags & CONVERTER_FLAGS_FLUSH) == CONVERTER_FLAGS_FLUSH;
220-
OnScopeLeave cleanup([&]() {
220+
auto cleanup = OnScopeLeave([&]() {
221221
if (flush) {
222222
// Reset the converter state.
223223
converter->bomSeen_ = false;

src/node_options.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
831831
per_process::cli_options->per_isolate = env->isolate_data()->options();
832832
auto original_per_env = per_process::cli_options->per_isolate->per_env;
833833
per_process::cli_options->per_isolate->per_env = env->options();
834-
OnScopeLeave on_scope_leave([&]() {
834+
auto on_scope_leave = OnScopeLeave([&]() {
835835
per_process::cli_options->per_isolate->per_env = original_per_env;
836836
per_process::cli_options->per_isolate = original_per_isolate;
837837
});

src/node_os.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
302302
return args.GetReturnValue().SetUndefined();
303303
}
304304

305-
OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); });
305+
auto free_passwd = OnScopeLeave([&]() { uv_os_free_passwd(&pwd); });
306306

307307
Local<Value> error;
308308

src/node_process_methods.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
355355
LPTHREAD_START_ROUTINE* handler = nullptr;
356356
DWORD pid = 0;
357357

358-
OnScopeLeave cleanup([&]() {
358+
auto cleanup = OnScopeLeave([&]() {
359359
if (process != nullptr) CloseHandle(process);
360360
if (thread != nullptr) CloseHandle(thread);
361361
if (handler != nullptr) UnmapViewOfFile(handler);

src/node_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void Worker::Run() {
182182
SealHandleScope outer_seal(isolate_);
183183

184184
DeleteFnPtr<Environment, FreeEnvironment> env_;
185-
OnScopeLeave cleanup_env([&]() {
185+
auto cleanup_env = OnScopeLeave([&]() {
186186
if (!env_) return;
187187
env_->set_can_call_into_js(false);
188188
Isolate::DisallowJavascriptExecutionScope disallow_js(isolate_,

src/node_zlib.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
386386
// v8 land!
387387
void AfterThreadPoolWork(int status) override {
388388
AllocScope alloc_scope(this);
389-
OnScopeLeave on_scope_leave([&]() { Unref(); });
389+
auto on_scope_leave = OnScopeLeave([&]() { Unref(); });
390390

391391
write_in_progress_ = false;
392392

0 commit comments

Comments
 (0)