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 <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
LiviaMedeiros authored and targos committed Jul 12, 2022
1 parent c359d7c commit 8e95cf7
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 @@ -149,16 +148,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 8e95cf7

Please sign in to comment.