Skip to content

Commit

Permalink
fix: refactor to simplify based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Apr 10, 2024
1 parent 96ba454 commit 76f07c4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/@lwc/engine-core/src/libs/mutation-tracker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ export class ReactiveObserver {
for (let i = 0; i < len; i++) {
const set = listeners[i];
const setLength = set.length;
if (setLength === 1) {
// Perf optimization for the common case - the length is usually 1, so avoid the indexOf+push.
// If the length is 1, we can also be sure that `this` is the first item in the array.
set.length = 0;
} else {
// Slow case - swap with the last item and then remove.
// The length is usually 1, so avoid doing an indexOf when we know for certain
// that `this` is the first item in the array.
if (setLength > 1) {
// Swap with the last item before removal.
// (Avoiding splice here is a perf optimization, and the order doesn't matter.)
const index = ArrayIndexOf.call(set, this);
set[index] = set[setLength - 1];
ArrayPop.call(set);
}
// Remove the last item
ArrayPop.call(set);
}
listeners.length = 0;
}
Expand Down

0 comments on commit 76f07c4

Please sign in to comment.