Skip to content

Commit

Permalink
src: avoid string copy in BuiltinLoader::GetBuiltinIds
Browse files Browse the repository at this point in the history
PR-URL: #48721
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
anonrig authored and RafaelGSS committed Aug 17, 2023
1 parent 3d36e7a commit db4370f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Local<String> BuiltinLoader::GetConfigString(Isolate* isolate) {
return config_.ToStringChecked(isolate);
}

std::vector<std::string> BuiltinLoader::GetBuiltinIds() const {
std::vector<std::string> ids;
std::vector<std::string_view> BuiltinLoader::GetBuiltinIds() const {
std::vector<std::string_view> ids;
auto source = source_.read();
ids.reserve(source->size());
for (auto const& x : *source) {
Expand All @@ -95,7 +95,7 @@ std::vector<std::string> BuiltinLoader::GetBuiltinIds() const {
BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
BuiltinCategories builtin_categories;

std::vector<std::string> prefixes = {
const std::vector<std::string_view> prefixes = {
#if !HAVE_OPENSSL
"internal/crypto/",
"internal/debugger/",
Expand Down Expand Up @@ -475,19 +475,19 @@ MaybeLocal<Value> BuiltinLoader::CompileAndCall(Local<Context> context,
}

bool BuiltinLoader::CompileAllBuiltins(Local<Context> context) {
std::vector<std::string> ids = GetBuiltinIds();
std::vector<std::string_view> ids = GetBuiltinIds();
bool all_succeeded = true;
std::string v8_tools_prefix = "internal/deps/v8/tools/";
for (const auto& id : ids) {
if (id.compare(0, v8_tools_prefix.size(), v8_tools_prefix) == 0) {
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);
}
Expand Down Expand Up @@ -607,7 +607,7 @@ void BuiltinLoader::BuiltinIdsGetter(Local<Name> property,
Environment* env = Environment::GetCurrent(info);
Isolate* isolate = env->isolate();

std::vector<std::string> ids = env->builtin_loader()->GetBuiltinIds();
std::vector<std::string_view> ids = env->builtin_loader()->GetBuiltinIds();
info.GetReturnValue().Set(
ToV8Value(isolate->GetCurrentContext(), ids).ToLocalChecked());
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader {
void LoadJavaScriptSource(); // Loads data into source_
UnionBytes GetConfig(); // Return data for config.gypi

std::vector<std::string> GetBuiltinIds() const;
std::vector<std::string_view> GetBuiltinIds() const;

struct BuiltinCategories {
std::set<std::string> can_be_required;
Expand Down

0 comments on commit db4370f

Please sign in to comment.