[cff] bsearch in fdselect
Saves 8% in NotoSansCJK / 10000 subset benchmark.
This commit is contained in:
parent
0c33aba30c
commit
ded9de9cd8
|
@ -476,14 +476,20 @@ struct FDSelect3_4
|
|||
return_trace (true);
|
||||
}
|
||||
|
||||
static int _cmp_range (const void *_key, const void *_item)
|
||||
{
|
||||
hb_codepoint_t glyph = * (hb_codepoint_t *) _key;
|
||||
FDSelect3_4_Range<GID_TYPE, FD_TYPE> *range = (FDSelect3_4_Range<GID_TYPE, FD_TYPE> *) _item;
|
||||
|
||||
if (glyph < range[0].first) return -1;
|
||||
if (glyph < range[1].first) return 0;
|
||||
return +1;
|
||||
}
|
||||
|
||||
hb_codepoint_t get_fd (hb_codepoint_t glyph) const
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 1; i < nRanges (); i++)
|
||||
if (glyph < ranges[i].first)
|
||||
break;
|
||||
|
||||
return (hb_codepoint_t) ranges[i - 1].fd;
|
||||
auto *range = hb_bsearch (glyph, &ranges[0], nRanges () - 1, sizeof (ranges[0]), _cmp_range);
|
||||
return range ? range->fd : ranges[nRanges () - 1].fd;
|
||||
}
|
||||
|
||||
GID_TYPE &nRanges () { return ranges.len; }
|
||||
|
|
|
@ -246,11 +246,10 @@ struct subr_flattener_t
|
|||
|
||||
bool flatten (str_buff_vec_t &flat_charstrings)
|
||||
{
|
||||
if (!flat_charstrings.resize (plan->num_output_glyphs ()))
|
||||
unsigned count = plan->num_output_glyphs ();
|
||||
if (!flat_charstrings.resize (count))
|
||||
return false;
|
||||
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
||||
flat_charstrings[i].init ();
|
||||
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
hb_codepoint_t glyph;
|
||||
if (!plan->old_gid_for_new_gid (i, &glyph))
|
||||
|
@ -266,7 +265,7 @@ struct subr_flattener_t
|
|||
ENV env (str, acc, fd);
|
||||
cs_interpreter_t<ENV, OPSET, flatten_param_t> interp (env);
|
||||
flatten_param_t param = {
|
||||
flat_charstrings[i],
|
||||
flat_charstrings.arrayZ[i],
|
||||
(bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
};
|
||||
if (unlikely (!interp.interpret (param)))
|
||||
|
|
Loading…
Reference in New Issue