fix: move cheaper check in front

This commit is contained in:
shirakaba
2022-12-21 16:31:58 +09:00
parent decccabd9e
commit 2a8c926509

View File

@@ -393,6 +393,17 @@ export class DOMEvent implements Event {
for (let i = this.listenersLazyCopy.length - 1; i >= 0; i--) { for (let i = this.listenersLazyCopy.length - 1; i >= 0; i--) {
const listener = this.listenersLazyCopy[i]; const listener = this.listenersLazyCopy[i];
// Assigning variables this old-fashioned way is up to 50
// nanoseconds faster per run than ESM destructuring syntax.
const capture = listener.capture;
// Handle only the events appropriate to the phase. Global events
// (a NativeScript-only concept) are allowed to be handled
// regardless of phase, for backwards-compatibility.
if (!isGlobal && ((phase === DOMEvent.CAPTURING_PHASE && !capture) || (phase === DOMEvent.BUBBLING_PHASE && capture))) {
continue;
}
// The event listener may have been removed since we took a copy of // The event listener may have been removed since we took a copy of
// the array, so bail out if so. // the array, so bail out if so.
// //
@@ -410,17 +421,6 @@ export class DOMEvent implements Event {
continue; continue;
} }
// Assigning variables this old-fashioned way is up to 50
// nanoseconds faster per run than ESM destructuring syntax.
const capture = listener.capture;
// Handle only the events appropriate to the phase. Global events
// (a NativeScript-only concept) are allowed to be handled
// regardless of phase, for backwards-compatibility.
if (!isGlobal && ((phase === DOMEvent.CAPTURING_PHASE && !capture) || (phase === DOMEvent.BUBBLING_PHASE && capture))) {
continue;
}
const callback = listener.callback; const callback = listener.callback;
const thisArg = listener.thisArg; const thisArg = listener.thisArg;