Optimize baseIndexOf more consistently.

This commit is contained in:
jdalton
2015-02-28 12:42:14 -08:00
parent 132aacee89
commit 63d5a3acbc

View File

@@ -314,14 +314,14 @@
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from. * @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */
function baseIndexOf(array, value, fromIndex) { function baseIndexOf(array, value, fromIndex) {
if (value !== value) { if (value !== value) {
return indexOfNaN(array, fromIndex); return indexOfNaN(array, fromIndex);
} }
var index = fromIndex == null ? -1 : (fromIndex - 1), var index = fromIndex - 1,
length = array.length; length = array.length;
while (++index < length) { while (++index < length) {
@@ -509,13 +509,13 @@
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {number} [fromIndex] The index to search from. * @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left. * @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched `NaN`, else `-1`. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
*/ */
function indexOfNaN(array, fromIndex, fromRight) { function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length, var length = array.length,
index = fromIndex == null ? (fromRight ? length : -1) : (fromIndex + (fromRight ? 0 : -1)); index = fromIndex + (fromRight ? 0 : -1);
while ((fromRight ? index-- : ++index < length)) { while ((fromRight ? index-- : ++index < length)) {
var other = array[index]; var other = array[index];
@@ -1991,7 +1991,7 @@
} }
result.push(value); result.push(value);
} }
else if (indexOf(values, value) < 0) { else if (indexOf(values, value, 0) < 0) {
result.push(value); result.push(value);
} }
} }
@@ -2817,7 +2817,7 @@
} }
result.push(value); result.push(value);
} }
else if (indexOf(seen, computed) < 0) { else if (indexOf(seen, computed, 0) < 0) {
if (iteratee || isLarge) { if (iteratee || isLarge) {
seen.push(computed); seen.push(computed);
} }
@@ -4725,14 +4725,14 @@
return -1; return -1;
} }
if (typeof fromIndex == 'number') { if (typeof fromIndex == 'number') {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
} else if (fromIndex) { } else if (fromIndex) {
var index = binaryIndex(array, value), var index = binaryIndex(array, value),
other = array[index]; other = array[index];
return (value === value ? value === other : other !== other) ? index : -1; return (value === value ? value === other : other !== other) ? index : -1;
} }
return baseIndexOf(array, value, fromIndex); return baseIndexOf(array, value, fromIndex || 0);
} }
/** /**
@@ -4795,11 +4795,11 @@
outer: outer:
while (++index < length) { while (++index < length) {
value = array[index]; value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) { if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
argsIndex = argsLength; argsIndex = argsLength;
while (--argsIndex) { while (--argsIndex) {
var cache = caches[argsIndex]; var cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) { if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
continue outer; continue outer;
} }
} }