merging in faster indexOf patch ... arguably faster than the native implementation, but oh well. #245

This commit is contained in:
Jeremy Ashkenas
2011-07-13 15:12:50 -04:00
parent 47fb3d7f9c
commit f099038a9d

View File

@@ -381,14 +381,13 @@
// for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) {
if (array == null) return -1;
var i, l;
var obj, i = 0;
if (isSorted) {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
var o,i=0;
while( o = array[i++] ) if (o === item) return i-1;
while (obj = array[i++]) if (obj === item) return i - 1;
return -1;
};