Skip to content

Commit

Permalink
tls: fix performance regression in convertALPNProtocols()
Browse files Browse the repository at this point in the history
`isUint8Array()` covers instances of `Buffer`
`isArrayBufferView()` path is cold and not worth additional check

PR-URL: #43250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 12, 2022
1 parent fff0560 commit 7f8f61a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const internalUtil = require('internal/util');
internalUtil.assertCrypto();
const {
isArrayBufferView,
isDataView,
isUint8Array,
} = require('internal/util/types');

Expand Down Expand Up @@ -148,16 +147,14 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) {
// If protocols is Array - translate it into buffer
if (ArrayIsArray(protocols)) {
out.ALPNProtocols = convertProtocols(protocols);
} else if (Buffer.isBuffer(protocols) || isUint8Array(protocols)) {
} else if (isUint8Array(protocols)) {
// Copy new buffer not to be modified by user.
out.ALPNProtocols = Buffer.from(protocols);
} else if (isDataView(protocols)) {
} else if (isArrayBufferView(protocols)) {
out.ALPNProtocols = Buffer.from(protocols.buffer.slice(
protocols.byteOffset,
protocols.byteOffset + protocols.byteLength
));
} else if (isArrayBufferView(protocols)) {
out.ALPNProtocols = Buffer.from(protocols.slice().buffer);
}
};

Expand Down

0 comments on commit 7f8f61a

Please sign in to comment.