mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
perf(webidl): optimize createRecordConverter() (#12286)
Cuts self-time by ~6x, 172ns/iter => 22ns/iter benched on 1M Response builds / HeadersInit calls
This commit is contained in:
parent
ea7a63cd5a
commit
5f41f822e7
1 changed files with 16 additions and 1 deletions
|
@ -9,6 +9,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
|
const core = window.Deno.core;
|
||||||
const {
|
const {
|
||||||
ArrayBuffer,
|
ArrayBuffer,
|
||||||
ArrayBufferIsView,
|
ArrayBufferIsView,
|
||||||
|
@ -48,6 +49,7 @@
|
||||||
ObjectGetOwnPropertyDescriptor,
|
ObjectGetOwnPropertyDescriptor,
|
||||||
ObjectGetOwnPropertyDescriptors,
|
ObjectGetOwnPropertyDescriptors,
|
||||||
ObjectGetPrototypeOf,
|
ObjectGetPrototypeOf,
|
||||||
|
ObjectPrototypeHasOwnProperty,
|
||||||
ObjectIs,
|
ObjectIs,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
PromiseReject,
|
PromiseReject,
|
||||||
|
@ -844,8 +846,21 @@
|
||||||
opts,
|
opts,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const keys = ReflectOwnKeys(V);
|
|
||||||
const result = {};
|
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) {
|
for (const key of keys) {
|
||||||
const desc = ObjectGetOwnPropertyDescriptor(V, key);
|
const desc = ObjectGetOwnPropertyDescriptor(V, key);
|
||||||
if (desc !== undefined && desc.enumerable === true) {
|
if (desc !== undefined && desc.enumerable === true) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue