Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: avoid string copy in BuiltinLoader::GetBuiltinIds #48721

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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