perf: prefer NewFromUtf8Literal() over NewFromUtf8() for string literals (#44412)

* perf: prefer NewFromUtf8Literal() over NewFromUtf8() for string literals

the string length is known at compile time and no need to call ToLocalChecked()

* perf: string length is known when calling NewFromUtf8(), so use it

* perf: remove unnecessary calls to c_str()

these just force the code being called to have to recalculate the string length
This commit is contained in:
Charles Kerr 2024-10-28 08:12:32 -05:00 committed by GitHub
parent 348801b20e
commit 5d0d15a0b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 24 deletions

View file

@ -57,7 +57,7 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
std::string binding_key = gin::V8ToString(isolate, key);
gin_helper::Dictionary cache(isolate, GetBindingCache(isolate));
if (cache.Get(binding_key.c_str(), &exports)) {
if (cache.Get(binding_key, &exports)) {
return exports;
}
@ -76,7 +76,7 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
DCHECK_NE(mod->nm_context_register_func, nullptr);
mod->nm_context_register_func(exports, v8::Null(isolate),
isolate->GetCurrentContext(), mod->nm_priv);
cache.Set(binding_key.c_str(), exports);
cache.Set(binding_key, exports);
return exports;
}