mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Disable use of basicIndexOf optimization if _.indexOf is customized.
Former-commit-id: 5b2273b36934581e34c6f6042de95bf556c61ca2
This commit is contained in:
29
lodash.js
29
lodash.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user