Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #571 from spadgos/sorted-index-caching

Cache iterator(obj) in sortedIndex
  • Loading branch information...
commit 2524e51ce7ec485d8ade482dec91e0b34718f57b 2 parents e1fc1d3 + ca0f211
@braddunbar braddunbar authored
Showing with 2 additions and 1 deletion.
  1. +2 −1  underscore.js
View
3  underscore.js
@@ -289,10 +289,11 @@
// an object should be inserted so as to maintain order. Uses binary search.
_.sortedIndex = function(array, obj, iterator) {
iterator || (iterator = _.identity);
+ obj = iterator(obj);
var low = 0, high = array.length;
while (low < high) {
var mid = (low + high) >> 1;
- iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid;
+ iterator(array[mid]) < obj ? low = mid + 1 : high = mid;
}
return low;
};
Please sign in to comment.
Something went wrong with that request. Please try again.