Optimize _.contains for arrays.

Former-commit-id: 050743f77e7047f86d5b14b97d35846c9d2e749c
This commit is contained in:
John-David Dalton
2013-08-26 22:32:20 -07:00
parent c3f5bc6bfb
commit ea8e6d978d
7 changed files with 29 additions and 25 deletions

View File

@@ -3028,12 +3028,13 @@
result = false;
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0;
if (length && typeof length == 'number') {
result = (isString(collection)
? collection.indexOf(target, fromIndex)
: indexOf(collection, target, fromIndex)
) > -1;
} else {
if (isArray(collection)) {
result = indexOf(collection, target, fromIndex) > -1;
}
else if (typeof length == 'number' && isString(collection)) {
result = collection.indexOf(target, fromIndex) > -1;
}
else {
baseEach(collection, function(value) {
if (++index >= fromIndex) {
return !(result = value === target);