From 96e53c6a43a64c47215d643fc87ad61ea4329def Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Tue, 20 Dec 2022 18:45:56 +0900 Subject: [PATCH] fix: declare onCurrentListenersMutation on prototype --- packages/core/data/dom-events/dom-event.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/data/dom-events/dom-event.ts b/packages/core/data/dom-events/dom-event.ts index bd307812f..8293b2af9 100644 --- a/packages/core/data/dom-events/dom-event.ts +++ b/packages/core/data/dom-events/dom-event.ts @@ -257,13 +257,19 @@ export class DOMEvent implements Event { // Creating this upon class construction as an arrow function rather than as // an inline function bound afresh on each usage saves about 210 nanoseconds - // per run of handleEvent(). - private onCurrentListenersMutation = () => { + // per run of dispatchTo(). + // + // Creating it on the prototype and calling with the context instead saves a + // further 125 nanoseconds per run of dispatchTo(). + // + // Creating it on the prototype and binding the context instead saves a + // further 30 nanoseconds per run of dispatchTo(). + private onCurrentListenersMutation() { // Cloning the array via spread syntax is up to 180 nanoseconds // faster per run than using Array.prototype.slice(). this.listenersLazyCopy = [...this.listenersLive]; this.listenersLive.onMutation = null; - }; + } /** * Dispatches a synthetic event event to target and returns true if either