Skip to content

Commit 20c534f

Browse files
committed
Switch loops to improve performance
1 parent 3b3816f commit 20c534f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/plot_api/helpers.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,22 @@ const hasCollectionChanged = (oldCollection, newCollection) => {
520520
if ([oldCollection, newCollection].every((a) => Array.isArray(a))) {
521521
if (oldCollection.length !== newCollection.length) return true;
522522

523-
return oldCollection.some((oldVal, i) => {
523+
for (let i = 0; i < oldCollection.length; i++) {
524+
const oldVal = oldCollection[i];
524525
const newVal = newCollection[i];
525526
if (oldVal !== newVal) return isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true;
526-
});
527+
}
527528
} else {
528529
if (Object.keys(oldCollection).length !== Object.keys(newCollection).length) return true;
529530

530-
return Object.keys(oldCollection).some((k) => {
531+
for (const k in oldCollection) {
531532
if (k.startsWith('_')) return false;
532533
const oldVal = oldCollection[k];
533534
const newVal = newCollection[k];
534535
if (oldVal !== newVal) return isArrayOrObject(oldVal, newVal) ? hasCollectionChanged(oldVal, newVal) : true;
535-
});
536+
}
536537
}
538+
539+
return false;
537540
};
538541
exports.hasCollectionChanged = hasCollectionChanged;

0 commit comments

Comments
 (0)