Skip to content

Commit

Permalink
Fix: Only do function call once
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartel-C8 committed Dec 6, 2022
1 parent 9fc16f2 commit 9de2a11
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/incoming_msg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ IncomingMsg::~IncomingMsg() {
}

Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
if (!hasElectronMemoryCage(env)) {
static auto const noElectronMemoryCage = !hasElectronMemoryCage(env);
if (noElectronMemoryCage) {
if (moved) {
/* If ownership has been transferred, do not attempt to read the buffer
again in any case. This should not happen of course. */
Expand All @@ -26,7 +27,7 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
auto data = reinterpret_cast<uint8_t*>(zmq_msg_data(*ref));
auto length = zmq_msg_size(*ref);

if (!hasElectronMemoryCage(env)) {
if (noElectronMemoryCage) {
static auto constexpr zero_copy_threshold = 1 << 7;
if (length > zero_copy_threshold) {
/* Reuse existing buffer for external storage. This avoids copying but
Expand Down

0 comments on commit 9de2a11

Please sign in to comment.