tls: fix performance regression in convertALPNProtocols()

`isUint8Array()` covers instances of `Buffer`
`isArrayBufferView()` path is cold and not worth additional check

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
LiviaMedeiros 2022-05-30 19:41:57 +08:00
parent ac27c58180
commit 386c7e126e
No known key found for this signature in database
GPG Key ID: 6E5412F8214FF24A

View File

@ -56,7 +56,6 @@ const internalUtil = require('internal/util');
internalUtil.assertCrypto();
const {
isArrayBufferView,
isDataView,
isUint8Array,
} = require('internal/util/types');
@ -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);
}
};