Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7d96ab0

Browse files
committed
perf(Scope): watchCollection optimization
tiny ~4ms improvement and code that minifies better
1 parent 0a738ce commit 7d96ab0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ng/rootScope.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ function $RootScopeProvider(){
517517

518518
function $watchCollectionInterceptor(_value) {
519519
newValue = _value;
520-
var newLength, key, bothNaN;
520+
var newLength, key, bothNaN, newItem, oldItem;
521521

522522
if (!isObject(newValue)) { // if primitive
523523
if (oldValue !== newValue) {
@@ -541,11 +541,13 @@ function $RootScopeProvider(){
541541
}
542542
// copy the items to oldValue and look for changes.
543543
for (var i = 0; i < newLength; i++) {
544-
bothNaN = (oldValue[i] !== oldValue[i]) &&
545-
(newValue[i] !== newValue[i]);
546-
if (!bothNaN && (oldValue[i] !== newValue[i])) {
544+
oldItem = oldValue[i];
545+
newItem = newValue[i];
546+
547+
bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
548+
if (!bothNaN && (oldItem !== newItem)) {
547549
changeDetected++;
548-
oldValue[i] = newValue[i];
550+
oldValue[i] = newItem;
549551
}
550552
}
551553
} else {

0 commit comments

Comments
 (0)