Skip to content

Commit ac78a90

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 56bbb8d commit ac78a90

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);
@@ -319,8 +326,8 @@ function createInterfaceConverter(name, prototype) {
319326

320327
converters.AlgorithmIdentifier = (V, opts) => {
321328
// Union for (object or DOMString)
322-
if (type(V) === 'Object') {
323-
return converters.object(V, opts);
329+
if (isObjectType(V)) {
330+
return V;
324331
}
325332
return converters.DOMString(V, opts);
326333
};

0 commit comments

Comments
 (0)