From 9ccaa19efc89af54e0901e64f6c26c967ff0d339 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 11 Aug 2023 11:31:58 -0400 Subject: [PATCH] src: avoid string copy in BuiltinLoader::GetBuiltinIds PR-URL: https://github.com/nodejs/node/pull/48721 Reviewed-By: Luigi Pinca Reviewed-By: Rafael Gonzaga --- src/node_builtins.cc | 14 +++++++------- src/node_builtins.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 875fb0979950b7..d78ad3dd811432 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -82,8 +82,8 @@ Local BuiltinLoader::GetConfigString(Isolate* isolate) { return config_.ToStringChecked(isolate); } -std::vector BuiltinLoader::GetBuiltinIds() const { - std::vector ids; +std::vector BuiltinLoader::GetBuiltinIds() const { + std::vector ids; auto source = source_.read(); ids.reserve(source->size()); for (auto const& x : *source) { @@ -95,7 +95,7 @@ std::vector BuiltinLoader::GetBuiltinIds() const { BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const { BuiltinCategories builtin_categories; - std::vector prefixes = { + const std::vector prefixes = { #if !HAVE_OPENSSL "internal/crypto/", "internal/debugger/", @@ -475,7 +475,7 @@ MaybeLocal BuiltinLoader::CompileAndCall(Local context, } bool BuiltinLoader::CompileAllBuiltins(Local context) { - std::vector ids = GetBuiltinIds(); + std::vector ids = GetBuiltinIds(); bool all_succeeded = true; std::string v8_tools_prefix = "internal/deps/v8/tools/"; for (const auto& id : ids) { @@ -483,11 +483,11 @@ bool BuiltinLoader::CompileAllBuiltins(Local context) { continue; } v8::TryCatch bootstrapCatch(context->GetIsolate()); - USE(LookupAndCompile(context, id.c_str(), nullptr)); + USE(LookupAndCompile(context, id.data(), nullptr)); if (bootstrapCatch.HasCaught()) { per_process::Debug(DebugCategory::CODE_CACHE, "Failed to compile code cache for %s\n", - id.c_str()); + id.data()); all_succeeded = false; PrintCaughtException(context->GetIsolate(), context, bootstrapCatch); } @@ -607,7 +607,7 @@ void BuiltinLoader::BuiltinIdsGetter(Local property, Environment* env = Environment::GetCurrent(info); Isolate* isolate = env->isolate(); - std::vector ids = env->builtin_loader()->GetBuiltinIds(); + std::vector ids = env->builtin_loader()->GetBuiltinIds(); info.GetReturnValue().Set( ToV8Value(isolate->GetCurrentContext(), ids).ToLocalChecked()); } diff --git a/src/node_builtins.h b/src/node_builtins.h index 5e634254fc6560..f91c2a8105bfe5 100644 --- a/src/node_builtins.h +++ b/src/node_builtins.h @@ -126,7 +126,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader { void LoadJavaScriptSource(); // Loads data into source_ UnionBytes GetConfig(); // Return data for config.gypi - std::vector GetBuiltinIds() const; + std::vector GetBuiltinIds() const; struct BuiltinCategories { std::set can_be_required;