1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

perf(fetch): optimize fillHeaders() key iteration (#12287)

Reduces self-time by ~70x (~70ms => ~1ms on 1M iters)

for...in filtered by hasOwnProperty yields the same set of keys as Object.keys()
This commit is contained in:
Aaron O'Mullan 2021-10-01 12:17:16 +02:00 committed by Ryan Dahl
parent 2f2302ed70
commit 774302b9bb

View file

@ -29,7 +29,7 @@
ArrayPrototypeJoin, ArrayPrototypeJoin,
ArrayPrototypeSplice, ArrayPrototypeSplice,
ArrayPrototypeFilter, ArrayPrototypeFilter,
ObjectKeys, ObjectPrototypeHasOwnProperty,
ObjectEntries, ObjectEntries,
RegExpPrototypeTest, RegExpPrototypeTest,
Symbol, Symbol,
@ -76,7 +76,10 @@
appendHeader(headers, header[0], header[1]); appendHeader(headers, header[0], header[1]);
} }
} else { } else {
for (const key of ObjectKeys(object)) { for (const key in object) {
if (!ObjectPrototypeHasOwnProperty(object, key)) {
continue;
}
appendHeader(headers, key, object[key]); appendHeader(headers, key, object[key]);
} }
} }