Optimize object comparisons in _.isEqual.

This commit is contained in:
jdalton
2015-05-03 19:38:58 -07:00
parent 14651d8ea8
commit ee182df533

View File

@@ -4007,29 +4007,22 @@
if (objLength != othLength && !isLoose) { if (objLength != othLength && !isLoose) {
return false; return false;
} }
var skipCtor = isLoose, var index = objLength;
index = -1; while (index--) {
var key = objProps[index];
while (++index < objLength) { if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
var key = objProps[index], return false;
result = isLoose ? key in other : hasOwnProperty.call(other, key);
if (result) {
var objValue = object[key],
othValue = other[key];
result = undefined;
if (customizer) {
result = isLoose
? customizer(othValue, objValue, key)
: customizer(objValue, othValue, key);
}
if (result === undefined) {
// Recursively compare objects (susceptible to call stack limits).
result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
}
} }
if (!result) { }
var skipCtor = isLoose;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key],
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
// Recursively compare objects (susceptible to call stack limits).
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
return false; return false;
} }
skipCtor || (skipCtor = key == 'constructor'); skipCtor || (skipCtor = key == 'constructor');