perf: improve temporaries in WebWorkerObserver::WorkerScriptReadyForEvaluation()
(#46377)
refactor: small refactor to WebWorkerObserver::WorkerScriptReadyForEvaluation() - replace a std::vector<std::string> local with a compile-time array of std::string_view - remove .c_str() pessimization when making v8 Strings from string_views Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
073df4e738
commit
15d2a7dc4c
1 changed files with 7 additions and 6 deletions
|
@ -4,9 +4,11 @@
|
|||
|
||||
#include "shell/renderer/web_worker_observer.h"
|
||||
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/strings/strcat.h"
|
||||
#include "base/threading/thread_local.h"
|
||||
#include "shell/common/api/electron_bindings.h"
|
||||
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||
|
@ -71,15 +73,14 @@ void WebWorkerObserver::WorkerScriptReadyForEvaluation(
|
|||
// is loaded. See corresponding change in node/init.ts.
|
||||
v8::Local<v8::Object> global = worker_context->Global();
|
||||
|
||||
std::vector<std::string> keys = {"fetch", "Response", "FormData",
|
||||
"Request", "Headers", "EventSource"};
|
||||
for (const auto& key : keys) {
|
||||
for (const std::string_view key :
|
||||
{"fetch", "Response", "FormData", "Request", "Headers", "EventSource"}) {
|
||||
v8::MaybeLocal<v8::Value> value =
|
||||
global->Get(worker_context, gin::StringToV8(isolate, key.c_str()));
|
||||
global->Get(worker_context, gin::StringToV8(isolate, key));
|
||||
if (!value.IsEmpty()) {
|
||||
std::string blink_key = "blink" + key;
|
||||
std::string blink_key = base::StrCat({"blink", key});
|
||||
global
|
||||
->Set(worker_context, gin::StringToV8(isolate, blink_key.c_str()),
|
||||
->Set(worker_context, gin::StringToV8(isolate, blink_key),
|
||||
value.ToLocalChecked())
|
||||
.Check();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue