perf(webidl): optimize createRecordConverter()
Cuts self-time by ~6x, 172ns/iter => 22ns/iter benched on 1M Response builds / HeadersInit calls
"use strict";
((window) => {
+ const core = window.Deno.core;
const {
ArrayBuffer,
ArrayBufferIsView,
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
+ ObjectPrototypeHasOwnProperty,
ObjectIs,
PromisePrototypeThen,
PromiseReject,
opts,
);
}
- const keys = ReflectOwnKeys(V);
const result = {};
+ // Fast path for common case (not a Proxy)
+ if (!core.isProxy(V)) {
+ for (const key in V) {
+ if (!ObjectPrototypeHasOwnProperty(V, key)) {
+ continue;
+ }
+ const typedKey = keyConverter(key, opts);
+ const value = V[key];
+ const typedValue = valueConverter(value, opts);
+ result[typedKey] = typedValue;
+ }
+ }
+ // Slow path if Proxy (e.g: in WPT tests)
+ const keys = ReflectOwnKeys(V);
for (const key of keys) {
const desc = ObjectGetOwnPropertyDescriptor(V, key);
if (desc !== undefined && desc.enumerable === true) {
