mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: swap spread for slice
This commit is contained in:
@@ -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];
|
||||||
|
|||||||
Reference in New Issue
Block a user