mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
Bug 1071448 - Speed up binary searches using a bitwise operation. r=adw
This commit is contained in:
parent
332c4fb2c9
commit
b2864affa3
@ -60,7 +60,8 @@ this.BinarySearch = Object.freeze({
|
||||
let low = 0;
|
||||
let high = array.length - 1;
|
||||
while (low <= high) {
|
||||
let mid = Math.floor((low + high) / 2);
|
||||
// Thanks to http://jsperf.com/code-review-1480 for this tip.
|
||||
let mid = (low + high) >> 1;
|
||||
let cmp = comparator(target, array[mid]);
|
||||
if (cmp == 0)
|
||||
return [true, mid];
|
||||
|
Loading…
x
Reference in New Issue
Block a user