summaryrefslogtreecommitdiff
path: root/ext/webidl/00_webidl.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-04 15:39:32 +0200
committerGitHub <noreply@github.com>2021-10-04 15:39:32 +0200
commit5f41f822e7ac64ebef41feaebc15c17b6d080958 (patch)
tree3d7a94b87f1b851d21709e6460196bbec88b5747 /ext/webidl/00_webidl.js
parentea7a63cd5aafcb20374688a2c7918fdc821ab113 (diff)
perf(webidl): optimize createRecordConverter() (#12286)
Cuts self-time by ~6x, 172ns/iter => 22ns/iter benched on 1M Response builds / HeadersInit calls
Diffstat (limited to 'ext/webidl/00_webidl.js')
-rw-r--r--ext/webidl/00_webidl.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index 08de5aba6..1bf9d776f 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -9,6 +9,7 @@
"use strict";
((window) => {
+ const core = window.Deno.core;
const {
ArrayBuffer,
ArrayBufferIsView,
@@ -48,6 +49,7 @@
ObjectGetOwnPropertyDescriptor,
ObjectGetOwnPropertyDescriptors,
ObjectGetPrototypeOf,
+ ObjectPrototypeHasOwnProperty,
ObjectIs,
PromisePrototypeThen,
PromiseReject,
@@ -844,8 +846,21 @@
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) {