[ReactNative] kill for...in array iteration in deepDiffer

This commit is contained in:
Spencer Ahrens
2015-04-17 15:47:22 -07:00
parent 65b6d209d9
commit ab1efbd4c1
2 changed files with 123 additions and 8 deletions

View File

@@ -35,16 +35,29 @@ var deepDiffer = function(one: any, two: any): bool {
if (one.constructor !== two.constructor) {
return true;
}
for (var key in one) {
if (deepDiffer(one[key], two[key])) {
if (Array.isArray(one)) {
// We know two is also an array because the constructors are equal
var len = one.length;
if (two.length !== len) {
return true;
}
}
for (var twoKey in two) {
// The only case we haven't checked yet is keys that are in two but aren't
// in one, which means they are different.
if (one[twoKey] === undefined && two[twoKey] !== undefined) {
return true;
for (var ii = 0; ii < len; ii++) {
if (deepDiffer(one[ii], two[ii])) {
return true;
}
}
} else {
for (var key in one) {
if (deepDiffer(one[key], two[key])) {
return true;
}
}
for (var twoKey in two) {
// The only case we haven't checked yet is keys that are in two but aren't
// in one, which means they are different.
if (one[twoKey] === undefined && two[twoKey] !== undefined) {
return true;
}
}
}
return false;