Skip to content

Commit 84e55cb

Browse files
Merge pull request #2122 from jridgewell/indexOf-lastIndexOf-code-sharing
Small indexOf Perf Boost
2 parents f468f6e + 7dfe96e commit 84e55cb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

underscore.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@
645645
length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
646646
}
647647
} else if (sortedIndex && idx && length) {
648-
idx = _[sortedIndex](array, item);
648+
idx = sortedIndex(array, item);
649649
return array[idx] === item ? idx : -1;
650650
}
651651
if (item !== item) {
652-
idx = _[predicateFind](slice.call(array, i, length), _.isNaN);
652+
idx = predicateFind(slice.call(array, i, length), _.isNaN);
653653
return idx >= 0 ? idx + i : -1;
654654
}
655655
for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
@@ -663,8 +663,8 @@
663663
// or -1 if the item is not included in the array.
664664
// If the array is large and already in sort order, pass `true`
665665
// for **isSorted** to use binary search.
666-
_.indexOf = createIndexFinder(1, 'findIndex', 'sortedIndex');
667-
_.lastIndexOf = createIndexFinder(-1, 'findLastIndex');
666+
_.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
667+
_.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
668668

669669
// Generate an integer Array containing an arithmetic progression. A port of
670670
// the native Python `range()` function. See

0 commit comments

Comments
 (0)