Disable use of basicIndexOf optimization if _.indexOf is customized.

Former-commit-id: 5b2273b36934581e34c6f6042de95bf556c61ca2
This commit is contained in:
John-David Dalton
2013-05-26 18:57:17 -07:00
parent 2e3b135fe9
commit e9387d322c
10 changed files with 402 additions and 260 deletions

View File

@@ -793,8 +793,9 @@
var bailout,
index = -1,
indexOf = getIndexOf(),
length = array.length,
isLarge = length >= largeArraySize,
isLarge = length >= largeArraySize && lodash.indexOf != indexOf,
objCache = {};
var caches = {
@@ -809,7 +810,7 @@
};
function basicContains(value) {
return basicIndexOf(array, value) > -1;
return indexOf(array, value) > -1;
}
function basicPush(value) {
@@ -957,6 +958,19 @@
return '\\' + stringEscapes[match];
}
/**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
* customized, this method returns the custom method, otherwise it returns
* the `basicIndexOf` function.
*
* @private
* @returns {Function} Returns the "indexOf" function.
*/
function getIndexOf(array, value, fromIndex) {
var result = (result = lodash.indexOf) == indexOf ? basicIndexOf : result;
return result;
}
/**
* Checks if `value` is a DOM node in IE < 9.
*
@@ -2300,7 +2314,8 @@
* // => { 'name': 'moe' }
*/
function omit(object, callback, thisArg) {
var isFunc = typeof callback == 'function',
var indexOf = getIndexOf(),
isFunc = typeof callback == 'function',
result = {};
if (isFunc) {
@@ -2311,7 +2326,7 @@
forIn(object, function(value, key, object) {
if (isFunc
? !callback(value, key, object)
: basicIndexOf(props, key) < 0
: indexOf(props, key) < 0
) {
result[key] = value;
}
@@ -2537,6 +2552,7 @@
*/
function contains(collection, target, fromIndex) {
var index = -1,
indexOf = getIndexOf(),
length = collection ? collection.length : 0,
result = false;
@@ -2544,7 +2560,7 @@
if (length && typeof length == 'number') {
result = (isString(collection)
? collection.indexOf(target, fromIndex)
: basicIndexOf(collection, target, fromIndex)
: indexOf(collection, target, fromIndex)
) > -1;
} else {
basicEach(collection, function(value) {
@@ -4240,6 +4256,7 @@
*/
var uniq = overloadWrapper(function(array, isSorted, callback) {
var index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
isLarge = !isSorted && length >= largeArraySize,
result = [],
@@ -4251,7 +4268,7 @@
if (isSorted
? !index || seen[seen.length - 1] !== computed
: (isLarge ? !seen.contains(computed) : basicIndexOf(seen, computed) < 0)
: (isLarge ? !seen.contains(computed) : indexOf(seen, computed) < 0)
) {
if (callback || isLarge) {
seen.push(computed);