Skip to content

Commit 56bbb8d

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 878126d commit 56bbb8d

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
@@ -273,7 +273,8 @@ function createDictionaryConverter(name, dictionaries) {
273273
return idlDict;
274274
}
275275

276-
for (const member of new SafeArrayIterator(allMembers)) {
276+
for (let i = 0; i < allMembers.length; i++) {
277+
const member = allMembers[i];
277278
const key = member.key;
278279

279280
let esMemberValue;
@@ -289,15 +290,15 @@ function createDictionaryConverter(name, dictionaries) {
289290
}`;
290291
const idlMemberValue = member.converter(esMemberValue, {
291292
__proto__: null,
292-
...opts,
293+
prefix: opts.prefix,
293294
context,
294295
});
295296
member.validator?.(idlMemberValue, esDict);
296297
setOwnProperty(idlDict, key, idlMemberValue);
297298
} else if (member.required) {
298299
throw makeException(
299300
`can not be converted to '${name}' because '${key}' is required in '${name}'.`,
300-
{ __proto__: null, ...opts, code: 'ERR_MISSING_OPTION' });
301+
{ __proto__: null, prefix: opts.prefix, context: opts.context, code: 'ERR_MISSING_OPTION' });
301302
}
302303
}
303304

0 commit comments

Comments
 (0)