Skip to content

Commit c23467e

Browse files
committed
crypto: reduce allocations in WebIDL dictionary converter
Replace SafeArrayIterator with index-based loop in the inner function returned by createDictionaryConverter, avoiding iterator object creation on every dictionary conversion. Replace object spread (`{ ...opts, context }`) with explicit property assignment when passing opts to member converters. This avoids allocating a full spread copy per dictionary member. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 8cf391a commit c23467e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/internal/crypto/webidl.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ function createDictionaryConverter(name, dictionaries) {
293293
return idlDict;
294294
}
295295

296-
for (const member of new SafeArrayIterator(allMembers)) {
296+
for (let i = 0; i < allMembers.length; i++) {
297+
const member = allMembers[i];
297298
const key = member.key;
298299

299300
let esMemberValue;
@@ -309,15 +310,15 @@ function createDictionaryConverter(name, dictionaries) {
309310
}`;
310311
const idlMemberValue = member.converter(esMemberValue, {
311312
__proto__: null,
312-
...opts,
313+
prefix: opts.prefix,
313314
context,
314315
});
315316
member.validator?.(idlMemberValue, esDict);
316317
setOwnProperty(idlDict, key, idlMemberValue);
317318
} else if (member.required) {
318319
throw makeException(
319320
`can not be converted to '${name}' because '${key}' is required in '${name}'.`,
320-
{ __proto__: null, ...opts, code: 'ERR_MISSING_OPTION' });
321+
{ __proto__: null, prefix: opts.prefix, context: opts.context, code: 'ERR_MISSING_OPTION' });
321322
}
322323
}
323324

0 commit comments

Comments
 (0)