From 4da9b64d49f1ae147c50d18b52d2382fb0368e99 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 19 Dec 2021 20:49:13 +0100 Subject: [PATCH] [perf] Skip masking and unmasking if the masking key is zero --- lib/receiver.js | 8 +++++++- lib/sender.js | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/receiver.js b/lib/receiver.js index e11e26618..2d29d62bb 100644 --- a/lib/receiver.js +++ b/lib/receiver.js @@ -417,7 +417,13 @@ class Receiver extends Writable { } data = this.consume(this._payloadLength); - if (this._masked) unmask(data, this._mask); + + if ( + this._masked && + (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0 + ) { + unmask(data, this._mask); + } } if (this._opcode > 0x07) return this.controlMessage(data); diff --git a/lib/sender.js b/lib/sender.js index 82cc662d6..54bab6622 100644 --- a/lib/sender.js +++ b/lib/sender.js @@ -107,6 +107,10 @@ class Sender { target[offset - 2] = mask[2]; target[offset - 1] = mask[3]; + if ((mask[0] | mask[1] | mask[2] | mask[3]) === 0) { + return [target, data]; + } + if (merge) { applyMask(data, mask, target, offset, data.length); return [target];