зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1071448 - Speed up binary searches using a bitwise operation. r=adw
This commit is contained in:
Родитель
332c4fb2c9
Коммит
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];
|
||||
|
|
Загрузка…
Ссылка в новой задаче