Optimize map and set comparisons in _.isEqual.

This commit is contained in:
John-David Dalton
2015-09-06 17:01:17 -07:00
parent dfd4ae9ea4
commit 38a16805ed

View File

@@ -2304,7 +2304,7 @@
isSameTag = objTag == othTag; isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) { if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag, equalFunc); return equalByTag(object, other, objTag, equalFunc, bitmask);
} }
var isPartial = bitmask & PARTIAL_COMPARE_FLAG; var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
if (!isPartial) { if (!isPartial) {
@@ -3753,9 +3753,10 @@
* @param {Object} other The other object to compare. * @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare. * @param {string} tag The `toStringTag` of the objects to compare.
* @param {Function} equalFunc The function to determine equivalents of values. * @param {Function} equalFunc The function to determine equivalents of values.
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/ */
function equalByTag(object, other, tag, equalFunc) { function equalByTag(object, other, tag, equalFunc, bitmask) {
switch (tag) { switch (tag) {
case boolTag: case boolTag:
case dateTag: case dateTag:
@@ -3782,8 +3783,10 @@
var convert = mapToArray; var convert = mapToArray;
case setTag: case setTag:
var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
convert || (convert = setToArray); convert || (convert = setToArray);
return equalFunc(convert(object), convert(other), undefined, UNORDERED_COMPARE_FLAG); return (isPartial || object.size == other.size) &&
equalFunc(convert(object), convert(other), undefined, bitmask | UNORDERED_COMPARE_FLAG);
} }
return false; return false;
} }