Skip to content

Commit

Permalink
[perf] Skip masking and unmasking if the masking key is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Dec 19, 2021
1 parent 7e87037 commit c15291a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/receiver.js
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/sender.js
Expand Up @@ -100,6 +100,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];
Expand Down

0 comments on commit c15291a

Please sign in to comment.