mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
perf: avoid a little extra work in InvokeIpcCallback() (#48456)
perf: two minor perf refactors in InvokeIpcCallback() 1. Allocate the CallbackScope on the stack instead of the heap 2. Skip a redundant call to node::Environment::GetCurrent()
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "electron/shell/renderer/electron_ipc_native.h"
|
#include "electron/shell/renderer/electron_ipc_native.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "base/trace_event/trace_event.h"
|
#include "base/trace_event/trace_event.h"
|
||||||
#include "shell/common/gin_converters/blink_converter.h"
|
#include "shell/common/gin_converters/blink_converter.h"
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
@@ -45,10 +47,9 @@ void InvokeIpcCallback(v8::Isolate* const isolate,
|
|||||||
|
|
||||||
// Only set up the node::CallbackScope if there's a node environment.
|
// Only set up the node::CallbackScope if there's a node environment.
|
||||||
// Sandboxed renderers don't have a node environment.
|
// Sandboxed renderers don't have a node environment.
|
||||||
std::unique_ptr<node::CallbackScope> callback_scope;
|
std::optional<node::CallbackScope> callback_scope;
|
||||||
if (node::Environment::GetCurrent(context)) {
|
if (auto* env = node::Environment::GetCurrent(context)) {
|
||||||
callback_scope = std::make_unique<node::CallbackScope>(
|
callback_scope.emplace(env, ipcNative, node::async_context{0, 0});
|
||||||
isolate, ipcNative, node::async_context{0, 0});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto callback_key = gin::ConvertToV8(isolate, callback_name)
|
auto callback_key = gin::ConvertToV8(isolate, callback_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user