Skip to content

Commit

Permalink
[perf] Prevent Sender.frame() from being deoptimized
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Apr 18, 2017
1 parent e182e96 commit 3dbb58a
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions lib/Sender.js
Expand Up @@ -140,11 +140,11 @@ class Sender {
*/
doClose (data, mask, cb) {
this.sendFrame(Sender.frame(data, {
readOnly: false,
opcode: 0x08,
rsv1: false,
fin: true,
mask
rsv1: false,
opcode: 0x08,
mask,
readOnly: false
}), cb);
}

Expand Down Expand Up @@ -186,11 +186,11 @@ class Sender {
*/
doPing (data, mask, readOnly) {
this.sendFrame(Sender.frame(data, {
opcode: 0x09,
rsv1: false,
fin: true,
readOnly,
mask
rsv1: false,
opcode: 0x09,
mask,
readOnly
}));
}

Expand Down Expand Up @@ -232,11 +232,11 @@ class Sender {
*/
doPong (data, mask, readOnly) {
this.sendFrame(Sender.frame(data, {
opcode: 0x0a,
rsv1: false,
fin: true,
readOnly,
mask
rsv1: false,
opcode: 0x0a,
mask,
readOnly
}));
}

Expand Down Expand Up @@ -283,26 +283,25 @@ class Sender {

if (this.perMessageDeflate) {
const opts = {
compress: this.compress,
mask: options.mask,
fin: options.fin,
readOnly,
rsv1,
opcode,
rsv1
mask: options.mask,
readOnly
};

if (this.deflating) {
this.enqueue([this.dispatch, data, opts, cb]);
this.enqueue([this.dispatch, data, this.compress, opts, cb]);
} else {
this.dispatch(data, opts, cb);
this.dispatch(data, this.compress, opts, cb);
}
} else {
this.sendFrame(Sender.frame(data, {
mask: options.mask,
fin: options.fin,
rsv1: false,
readOnly,
opcode
opcode,
mask: options.mask,
readOnly
}), cb);
}
}
Expand All @@ -311,18 +310,18 @@ class Sender {
* Dispatches a data message.
*
* @param {Buffer} data The message to send
* @param {Boolean} compress Specifies whether or not to compress `data`
* @param {Object} options Options object
* @param {Number} options.opcode The opcode
* @param {Boolean} options.readOnly Specifies whether `data` can be modified
* @param {Boolean} options.fin Specifies whether or not to set the FIN bit
* @param {Boolean} options.compress Specifies whether or not to compress `data`
* @param {Boolean} options.mask Specifies whether or not to mask `data`
* @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
* @param {Function} cb Callback
* @private
*/
dispatch (data, options, cb) {
if (!options.compress) {
dispatch (data, compress, options, cb) {
if (!compress) {
this.sendFrame(Sender.frame(data, options), cb);
return;
}
Expand Down

0 comments on commit 3dbb58a

Please sign in to comment.