Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit decccab

Browse filesBrowse files
committed
fix: assign variables as late as possible
1 parent 569b1f2 commit decccab
Copy full SHA for decccab

File tree

Expand file treeCollapse file tree

1 file changed

+13
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-11
lines changed

‎packages/core/data/dom-events/dom-event.ts

Copy file name to clipboardExpand all lines: packages/core/data/dom-events/dom-event.ts
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class DOMEvent implements Event {
121121

122122
// Strictly speaking, we should use { public get, private set } for all of
123123
// `eventPhase`, `currentTarget`, and `target`, but using simple properties
124-
// saves 800 nanoseconds per run of handleEvent() (and so is one of our
124+
// saves 800 nanoseconds per run of dispatchTo() (and so is one of our
125125
// biggest optimisations).
126126

127127
/**
@@ -393,14 +393,6 @@ export class DOMEvent implements Event {
393393
for (let i = this.listenersLazyCopy.length - 1; i >= 0; i--) {
394394
const listener = this.listenersLazyCopy[i];
395395

396-
// Assigning variables this old-fashioned way is up to 50
397-
// nanoseconds faster per run than ESM destructuring syntax.
398-
const callback = listener.callback;
399-
const capture = listener.capture;
400-
const thisArg = listener.thisArg;
401-
const once = listener.once;
402-
const passive = listener.once;
403-
404396
// The event listener may have been removed since we took a copy of
405397
// the array, so bail out if so.
406398
//
@@ -418,14 +410,21 @@ export class DOMEvent implements Event {
418410
continue;
419411
}
420412

413+
// Assigning variables this old-fashioned way is up to 50
414+
// nanoseconds faster per run than ESM destructuring syntax.
415+
const capture = listener.capture;
416+
421417
// Handle only the events appropriate to the phase. Global events
422418
// (a NativeScript-only concept) are allowed to be handled
423419
// regardless of phase, for backwards-compatibility.
424420
if (!isGlobal && ((phase === DOMEvent.CAPTURING_PHASE && !capture) || (phase === DOMEvent.BUBBLING_PHASE && capture))) {
425421
continue;
426422
}
427423

428-
if (once) {
424+
const callback = listener.callback;
425+
const thisArg = listener.thisArg;
426+
427+
if (listener.once) {
429428
// Calling with the context (rather than eagerly pre-binding it)
430429
// saves about 100 nanoseconds per dispatchTo() call.
431430
removeEventListener.call(removeEventListenerContext, this.type, callback, thisArg, capture);
@@ -441,11 +440,14 @@ export class DOMEvent implements Event {
441440

442441
// This ensures that errors thrown inside asynchronous functions do
443442
// not get swallowed.
443+
//
444+
// This check costs only 25 nanoseconds per dispatchTo(), so is not
445+
// a huge deal.
444446
if (returnValue instanceof Promise) {
445447
returnValue.catch(console.error);
446448
}
447449

448-
if (passive && this.defaultPrevented) {
450+
if (listener.passive && this.defaultPrevented) {
449451
console.warn('Unexpected call to event.preventDefault() in passive event listener.');
450452
}
451453

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.