[subset] Write CoverageFormat2::intersects_coverage() as bsearch()
This commit is contained in:
parent
63c6695108
commit
c476f58adb
|
@ -1552,16 +1552,21 @@ struct CoverageFormat2
|
||||||
}
|
}
|
||||||
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
|
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
|
||||||
{
|
{
|
||||||
/* TODO Use bsearch? */
|
auto cmp = [] (const void *pk, const void *pr) -> int
|
||||||
for (const auto& range : rangeRecord.as_array ())
|
|
||||||
{
|
{
|
||||||
if (range.value <= index &&
|
unsigned index = * (const unsigned *) pk;
|
||||||
index < (unsigned int) range.value + (range.last - range.first) &&
|
const RangeRecord &range = * (const RangeRecord *) pr;
|
||||||
range.intersects (glyphs))
|
if (index < range.value) return -1;
|
||||||
return true;
|
if (index > (unsigned int) range.value + (range.last - range.first)) return +1;
|
||||||
else if (index < range.value)
|
return 0;
|
||||||
return false;
|
};
|
||||||
}
|
|
||||||
|
auto arr = rangeRecord.as_array ();
|
||||||
|
unsigned idx;
|
||||||
|
if (hb_bsearch_impl (&idx, index,
|
||||||
|
arr.arrayZ, arr.length, sizeof (arr[0]),
|
||||||
|
(int (*)(const void *_key, const void *_item)) cmp))
|
||||||
|
return arr.arrayZ[idx].intersects (glyphs);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue