fix: swap spread for slice

This commit is contained in:
shirakaba
2022-12-21 21:42:31 +09:00
parent d3d6830813
commit 959f0a2204

View File

@@ -365,8 +365,14 @@ export class DOMEvent implements Event {
// Taking multiple params instead of a single property bag saves 250 // Taking multiple params instead of a single property bag saves 250
// nanoseconds per dispatchTo() call. // nanoseconds per dispatchTo() call.
private handleEvent(data: EventData, isGlobal: boolean, phase: 0 | 1 | 2 | 3, removeEventListener: (eventName: string, callback?: any, thisArg?: any, capture?: boolean) => void, removeEventListenerContext: unknown) { private handleEvent(data: EventData, isGlobal: boolean, phase: 0 | 1 | 2 | 3, removeEventListener: (eventName: string, callback?: any, thisArg?: any, capture?: boolean) => void, removeEventListenerContext: unknown) {
// Clone the array just before any mutations. // Clone the array just before any mutations. I tried swapping this out
const listeners = [...this.listeners]; // for a copy-on-write array, but as it had to maintain its own array of
// listeners for any write actions, it actually ran significantly
// slower.
//
// There's no clear observable difference between array spread and slice
// here, but I think slice has reason to run faster.
const listeners = this.listeners.slice();
for (let i = listeners.length - 1; i >= 0; i--) { for (let i = listeners.length - 1; i >= 0; i--) {
const listener = listeners[i]; const listener = listeners[i];