[gsubgpos] Refactor skippy_iter.match()

This commit is contained in:
Behdad Esfahbod 2023-02-06 13:08:52 -07:00
parent ef2a8f722f
commit b29fbd16fa
1 changed files with 54 additions and 40 deletions

View File

@ -532,6 +532,30 @@ struct hb_ot_apply_context_t :
may_skip (const hb_glyph_info_t &info) const may_skip (const hb_glyph_info_t &info) const
{ return matcher.may_skip (c, info); } { return matcher.may_skip (c, info); }
enum match_t {
MATCH,
NOT_MATCH,
SKIP
};
match_t match (hb_glyph_info_t &info)
{
matcher_t::may_skip_t skip = matcher.may_skip (c, info);
if (unlikely (skip == matcher_t::SKIP_YES))
return SKIP;
matcher_t::may_match_t match = matcher.may_match (info, get_glyph_data ());
if (match == matcher_t::MATCH_YES ||
(match == matcher_t::MATCH_MAYBE &&
skip == matcher_t::SKIP_NO))
return MATCH;
if (skip == matcher_t::SKIP_NO)
return NOT_MATCH;
return SKIP;
}
bool next (unsigned *unsafe_to = nullptr) bool next (unsigned *unsafe_to = nullptr)
{ {
assert (num_items > 0); assert (num_items > 0);
@ -543,28 +567,23 @@ struct hb_ot_apply_context_t :
while ((signed) idx < stop) while ((signed) idx < stop)
{ {
idx++; idx++;
hb_glyph_info_t &info = c->buffer->info[idx]; switch (match (c->buffer->info[idx]))
{
matcher_t::may_skip_t skip = matcher.may_skip (c, info); case MATCH:
if (unlikely (skip == matcher_t::SKIP_YES))
continue;
matcher_t::may_match_t match = matcher.may_match (info, get_glyph_data ());
if (match == matcher_t::MATCH_YES ||
(match == matcher_t::MATCH_MAYBE &&
skip == matcher_t::SKIP_NO))
{ {
num_items--; num_items--;
advance_glyph_data (); advance_glyph_data ();
return true; return true;
} }
case NOT_MATCH:
if (skip == matcher_t::SKIP_NO)
{ {
if (unsafe_to) if (unsafe_to)
*unsafe_to = idx + 1; *unsafe_to = idx + 1;
return false; return false;
} }
case SKIP:
continue;
}
} }
if (unsafe_to) if (unsafe_to)
*unsafe_to = end; *unsafe_to = end;
@ -588,28 +607,23 @@ struct hb_ot_apply_context_t :
while (idx > stop) while (idx > stop)
{ {
idx--; idx--;
hb_glyph_info_t &info = c->buffer->out_info[idx]; switch (match (c->buffer->out_info[idx]))
{
matcher_t::may_skip_t skip = matcher.may_skip (c, info); case MATCH:
if (unlikely (skip == matcher_t::SKIP_YES))
continue;
matcher_t::may_match_t match = matcher.may_match (info, get_glyph_data ());
if (match == matcher_t::MATCH_YES ||
(match == matcher_t::MATCH_MAYBE &&
skip == matcher_t::SKIP_NO))
{ {
num_items--; num_items--;
advance_glyph_data (); advance_glyph_data ();
return true; return true;
} }
case NOT_MATCH:
if (skip == matcher_t::SKIP_NO)
{ {
if (unsafe_from) if (unsafe_from)
*unsafe_from = hb_max (1u, idx) - 1u; *unsafe_from = hb_max (1u, idx) - 1u;
return false; return false;
} }
case SKIP:
continue;
}
} }
if (unsafe_from) if (unsafe_from)
*unsafe_from = 0; *unsafe_from = 0;