mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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:
parent
ac27c58180
commit
386c7e126e
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user