Cleanup baseIsMatch and equalArrays.

This commit is contained in:
jdalton
2015-05-02 23:00:57 -07:00
parent 7b80a780c7
commit 13fe88c03f

View File

@@ -2438,11 +2438,11 @@
* @returns {boolean} Returns `true` if `object` is a match, else `false`. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/ */
function baseIsMatch(object, props, values, strictCompareFlags, customizer) { function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
var index = -1, var length = props.length,
length = props.length, index = length,
noCustomizer = !customizer; noCustomizer = !customizer;
while (++index < length) { while (index--) {
if ((noCustomizer && strictCompareFlags[index]) if ((noCustomizer && strictCompareFlags[index])
? values[index] !== object[props[index]] ? values[index] !== object[props[index]]
: !(props[index] in object) : !(props[index] in object)
@@ -2450,22 +2450,20 @@
return false; return false;
} }
} }
index = -1;
while (++index < length) { while (++index < length) {
var key = props[index], var key = props[index],
objValue = object[key], objValue = object[key],
srcValue = values[index]; srcValue = values[index];
if (noCustomizer && strictCompareFlags[index]) { if (noCustomizer && strictCompareFlags[index]) {
var result = objValue !== undefined || (key in object); if (objValue === undefined && !(key in object)) {
} else { return false;
result = customizer ? customizer(objValue, srcValue, key) : undefined; }
if (result === undefined) { } else {
result = baseIsEqual(srcValue, objValue, customizer, true); var result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
return false;
} }
}
if (!result) {
return false;
} }
} }
return true; return true;
@@ -2562,7 +2560,7 @@
} }
return object[key] === value return object[key] === value
? (value !== undefined || (key in object)) ? (value !== undefined || (key in object))
: baseIsEqual(value, object[key], null, true); : baseIsEqual(value, object[key], undefined, true);
}; };
} }
@@ -3263,11 +3261,11 @@
customizer = bindCallback(customizer, thisArg, 5); customizer = bindCallback(customizer, thisArg, 5);
length -= 2; length -= 2;
} else { } else {
customizer = typeof thisArg == 'function' ? thisArg : null; customizer = typeof thisArg == 'function' ? thisArg : undefined;
length -= (customizer ? 1 : 0); length -= (customizer ? 1 : 0);
} }
if (guard && isIterateeCall(sources[0], sources[1], guard)) { if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? null : customizer; customizer = length < 3 ? undefined : customizer;
length = 1; length = 1;
} }
while (++index < length) { while (++index < length) {
@@ -3919,40 +3917,32 @@
function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) { function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
var index = -1, var index = -1,
arrLength = array.length, arrLength = array.length,
othLength = other.length, othLength = other.length;
result = true;
if (arrLength != othLength && !(isLoose && othLength > arrLength)) { if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
return false; return false;
} }
// Deep compare the contents, ignoring non-numeric properties. // Ignore non-index properties.
while (result && ++index < arrLength) { while (++index < arrLength) {
var arrValue = array[index], var arrValue = array[index],
othValue = other[index]; othValue = other[index],
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
result = undefined; if (result !== undefined && !result) {
if (customizer) { return false;
result = isLoose
? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index);
} }
if (result === undefined) { // Recursively compare arrays (susceptible to call stack limits).
// Recursively compare arrays (susceptible to call stack limits). if (isLoose) {
if (isLoose) { if (!arraySome(other, function(othValue) {
var othIndex = othLength; return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
while (othIndex--) { })) {
othValue = other[othIndex]; return false;
result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
if (result) {
break;
}
}
} else {
result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
} }
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
return false;
} }
} }
return !!result; return true;
} }
/** /**
@@ -8567,7 +8557,7 @@
customizer = isDeep; customizer = isDeep;
isDeep = false; isDeep = false;
} }
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 1) : undefined;
return baseClone(value, isDeep, customizer); return baseClone(value, isDeep, customizer);
} }
@@ -8617,7 +8607,7 @@
* // => 20 * // => 20
*/ */
function cloneDeep(value, customizer, thisArg) { function cloneDeep(value, customizer, thisArg) {
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 1) : undefined;
return baseClone(value, true, customizer); return baseClone(value, true, customizer);
} }
@@ -8817,7 +8807,7 @@
* // => true * // => true
*/ */
function isEqual(value, other, customizer, thisArg) { function isEqual(value, other, customizer, thisArg) {
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
if (!customizer && isStrictComparable(value) && isStrictComparable(other)) { if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
return value === other; return value === other;
} }
@@ -8976,7 +8966,7 @@
if (object == null) { if (object == null) {
return false; return false;
} }
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3); customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
object = toObject(object); object = toObject(object);
if (!customizer && length == 1) { if (!customizer && length == 1) {
var key = props[0], var key = props[0],