Skip to content

Commit 2aeeb35

Browse files
committed
Fix: Only do function call once
1 parent 70d00a6 commit 2aeeb35

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/incoming_msg.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ IncomingMsg::~IncomingMsg() {
1515
}
1616

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

29-
if (!hasElectronMemoryCage(env)) {
30+
if (noElectronMemoryCage) {
3031
static auto constexpr zero_copy_threshold = 1 << 7;
3132
if (length > zero_copy_threshold) {
3233
/* Reuse existing buffer for external storage. This avoids copying but

0 commit comments

Comments
 (0)