refactor(math-kern): call hb_bsearch_impl instead of raw binary search

pull/4551/head
Lie Yan 1 year ago committed by Behdad Esfahbod
parent b42b112456
commit 155015f4be
  1. 25
      src/hb-ot-math-table.hh

@ -347,22 +347,17 @@ struct MathKern
/* According to OpenType spec (v1.9), except for the boundary cases, the index
* chosen for kern value should be i such that
* correctionHeight[i-1] <= correction_height < correctionHeight[i]
* We can just use the binary search algorithm of std::upper_bound(), which
* matches the spec, including for the boundary cases.
* We can use the binary search algorithm of std::upper_bound(). Or, we can
* use the internal hb_bsearch_impl.
*/
unsigned int i = 0;
unsigned int count = heightCount;
while (count > 0)
{
unsigned int half = count / 2;
hb_position_t height = correctionHeight[i + half].get_y_value (font, this);
if (sign * height <= sign * correction_height)
{
i += half + 1;
count -= half + 1;
} else
count = half;
}
unsigned int pos;
auto cmp = +[](const void* key, const void* p,
int sign, hb_font_t* font, const MathKern* mathKern) -> int {
return sign * *(hb_position_t*)key - sign * ((MathValueRecord*)p)->get_y_value(font, mathKern);
};
unsigned int i = hb_bsearch_impl(&pos, correction_height, correctionHeight,
heightCount, MathValueRecord::static_size,
cmp, sign, font, this) ? pos + 1 : pos;
return kernValue[i].get_x_value (font, this);
}

Loading…
Cancel
Save