parent
97b9268577
commit
33d38e793e
|
@ -139,7 +139,7 @@ hb_aat_layout_find_feature_mapping (hb_tag_t tag)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (const hb_aat_feature_mapping_t *) bsearch (&tag,
|
return (const hb_aat_feature_mapping_t *) hb_bsearch (&tag,
|
||||||
feature_mappings,
|
feature_mappings,
|
||||||
ARRAY_LENGTH (feature_mappings),
|
ARRAY_LENGTH (feature_mappings),
|
||||||
sizeof (feature_mappings[0]),
|
sizeof (feature_mappings[0]),
|
||||||
|
|
|
@ -603,40 +603,19 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
|
||||||
/*
|
/*
|
||||||
* Sort and search.
|
* Sort and search.
|
||||||
*/
|
*/
|
||||||
|
template <typename ...Ts>
|
||||||
static inline void *
|
static inline void *
|
||||||
hb_bsearch (const void *key, const void *base,
|
hb_bsearch (const void *key, const void *base,
|
||||||
size_t nmemb, size_t size,
|
size_t nmemb, size_t size,
|
||||||
int (*compar)(const void *_key, const void *_item))
|
int (*compar)(const void *_key, const void *_item, Ts... args),
|
||||||
|
Ts... args)
|
||||||
{
|
{
|
||||||
int min = 0, max = (int) nmemb - 1;
|
int min = 0, max = (int) nmemb - 1;
|
||||||
while (min <= max)
|
while (min <= max)
|
||||||
{
|
{
|
||||||
int mid = (min + max) / 2;
|
int mid = (min + max) / 2;
|
||||||
const void *p = (const void *) (((const char *) base) + (mid * size));
|
const void *p = (const void *) (((const char *) base) + (mid * size));
|
||||||
int c = compar (key, p);
|
int c = compar (key, p, args...);
|
||||||
if (c < 0)
|
|
||||||
max = mid - 1;
|
|
||||||
else if (c > 0)
|
|
||||||
min = mid + 1;
|
|
||||||
else
|
|
||||||
return (void *) p;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *
|
|
||||||
hb_bsearch_r (const void *key, const void *base,
|
|
||||||
size_t nmemb, size_t size,
|
|
||||||
int (*compar)(const void *_key, const void *_item, void *_arg),
|
|
||||||
void *arg)
|
|
||||||
{
|
|
||||||
int min = 0, max = (int) nmemb - 1;
|
|
||||||
while (min <= max)
|
|
||||||
{
|
|
||||||
int mid = ((unsigned int) min + (unsigned int) max) / 2;
|
|
||||||
const void *p = (const void *) (((const char *) base) + (mid * size));
|
|
||||||
int c = compar (key, p, arg);
|
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
else if (c > 0)
|
else if (c > 0)
|
||||||
|
|
|
@ -168,7 +168,7 @@ struct post
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_bytes_t st (name, len);
|
hb_bytes_t st (name, len);
|
||||||
const uint16_t *gid = (const uint16_t *) hb_bsearch_r (hb_addressof (st), gids, count,
|
const uint16_t *gid = (const uint16_t *) hb_bsearch (hb_addressof (st), gids, count,
|
||||||
sizeof (gids[0]), cmp_key, (void *) this);
|
sizeof (gids[0]), cmp_key, (void *) this);
|
||||||
if (gid)
|
if (gid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct MVAR
|
||||||
const int *coords, unsigned int coord_count) const
|
const int *coords, unsigned int coord_count) const
|
||||||
{
|
{
|
||||||
const VariationValueRecord *record;
|
const VariationValueRecord *record;
|
||||||
record = (VariationValueRecord *) bsearch (&tag, valuesZ.arrayZ,
|
record = (VariationValueRecord *) hb_bsearch (&tag, valuesZ.arrayZ,
|
||||||
valueRecordCount, valueRecordSize,
|
valueRecordCount, valueRecordSize,
|
||||||
tag_compare);
|
tag_compare);
|
||||||
if (!record)
|
if (!record)
|
||||||
|
|
Loading…
Reference in New Issue