Skip to content

Commit 6cba07e

Browse files
committed
crypto: skip string tag allocation in AlgorithmIdentifier fast path
Use a direct `typeof` check in `converters.object` and `converters.AlgorithmIdentifier` instead of the generic `type()` helper, which returned an intermediate 'Object' / 'Null' / ... string tag. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 41c3e29 commit 6cba07e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/internal/crypto/webidl.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ function type(V) {
9595
}
9696
}
9797

98+
// Fast check for the WebIDL Object type: a non-null object or a function.
99+
// Equivalent to `type(V) === 'Object'` but avoids allocating and comparing
100+
// the intermediate string tag on hot paths.
101+
function isObjectType(V) {
102+
return V !== null && (typeof V === 'object' || typeof V === 'function');
103+
}
104+
98105
const integerPart = MathTrunc;
99106

100107
function validateByteLength(buf, name, target) {
@@ -184,7 +191,7 @@ converters.DOMString = function(V, opts = kEmptyObject) {
184191
};
185192

186193
converters.object = (V, opts) => {
187-
if (type(V) !== 'Object') {
194+
if (!isObjectType(V)) {
188195
throw makeException(
189196
'is not an object.',
190197
opts);
@@ -339,8 +346,8 @@ function createInterfaceConverter(name, prototype) {
339346

340347
converters.AlgorithmIdentifier = (V, opts) => {
341348
// Union for (object or DOMString)
342-
if (type(V) === 'Object') {
343-
return converters.object(V, opts);
349+
if (isObjectType(V)) {
350+
return V;
344351
}
345352
return converters.DOMString(V, opts);
346353
};

0 commit comments

Comments
 (0)