mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-17 02:41:49 +08:00
perf(Scope): optimize $watchCollection when used for watching objects
Since we control the oldValue, we don't need to worry about proto-inhereted properties which means we can use 'for in' and skip hasOwnProperty checks. http://jsperf.com/for-in-vs-object-keys2
This commit is contained in:
@@ -562,16 +562,18 @@ function $RootScopeProvider(){
|
||||
for (key in newValue) {
|
||||
if (newValue.hasOwnProperty(key)) {
|
||||
newLength++;
|
||||
if (oldValue.hasOwnProperty(key)) {
|
||||
bothNaN = (oldValue[key] !== oldValue[key]) &&
|
||||
(newValue[key] !== newValue[key]);
|
||||
if (!bothNaN && (oldValue[key] !== newValue[key])) {
|
||||
newItem = newValue[key];
|
||||
oldItem = oldValue[key];
|
||||
|
||||
if (key in oldValue) {
|
||||
bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
|
||||
if (!bothNaN && (oldItem !== newItem)) {
|
||||
changeDetected++;
|
||||
oldValue[key] = newValue[key];
|
||||
oldValue[key] = newItem;
|
||||
}
|
||||
} else {
|
||||
oldLength++;
|
||||
oldValue[key] = newValue[key];
|
||||
oldValue[key] = newItem;
|
||||
changeDetected++;
|
||||
}
|
||||
}
|
||||
@@ -580,7 +582,7 @@ function $RootScopeProvider(){
|
||||
// we used to have more keys, need to find them and destroy them.
|
||||
changeDetected++;
|
||||
for(key in oldValue) {
|
||||
if (oldValue.hasOwnProperty(key) && !newValue.hasOwnProperty(key)) {
|
||||
if (!newValue.hasOwnProperty(key)) {
|
||||
oldLength--;
|
||||
delete oldValue[key];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user