From 569b1f2de3331938b3cd5e123a49f023c6725fae Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Wed, 21 Dec 2022 16:16:47 +0900 Subject: [PATCH] fix: determine insertion function up-front --- packages/core/data/dom-events/dom-event.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/data/dom-events/dom-event.ts b/packages/core/data/dom-events/dom-event.ts index b5cc7fad2..4d7052165 100644 --- a/packages/core/data/dom-events/dom-event.ts +++ b/packages/core/data/dom-events/dom-event.ts @@ -208,9 +208,13 @@ export class DOMEvent implements Event { return recycledEventPath; } + // Determining the function up-front (rather than inside the loop) saves + // 50 nanoseconds per dispatchTo() call. + const insert = path === 'capture' ? recycledEventPath.unshift.bind(recycledEventPath) : recycledEventPath.push.bind(recycledEventPath); + let nextResponder = responder.parent; while (nextResponder) { - path === 'capture' ? recycledEventPath.unshift(nextResponder) : recycledEventPath.push(nextResponder); + insert(nextResponder); // TODO: decide whether to walk up from Page to Frame, and whether // to then walk from Frame to Application or something.