[layout] Simplify StructAfter<> usage

This commit is contained in:
Behdad Esfahbod 2022-07-08 14:08:51 -06:00
parent 5192294f83
commit 6d051f4018
1 changed files with 54 additions and 53 deletions

View File

@ -2709,8 +2709,8 @@ struct ChainRule
{
bool intersects (const hb_set_t *glyphs, ChainContextClosureLookupContext &lookup_context) const
{
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
return chain_context_intersects (glyphs,
backtrack.len, backtrack.arrayZ,
input.lenP1, input.arrayZ,
@ -2723,9 +2723,9 @@ struct ChainRule
{
if (unlikely (c->lookup_limit_exceeded ())) return;
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
chain_context_closure_lookup (c,
backtrack.len, backtrack.arrayZ,
input.lenP1, input.arrayZ,
@ -2741,18 +2741,18 @@ struct ChainRule
if (unlikely (c->lookup_limit_exceeded ())) return;
if (!intersects (c->glyphs, lookup_context)) return;
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
recurse_lookups (c, lookup.len, lookup.arrayZ);
}
void collect_glyphs (hb_collect_glyphs_context_t *c,
ChainContextCollectGlyphsLookupContext &lookup_context) const
{
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
chain_context_collect_glyphs_lookup (c,
backtrack.len, backtrack.arrayZ,
input.lenP1, input.arrayZ,
@ -2764,9 +2764,9 @@ struct ChainRule
bool would_apply (hb_would_apply_context_t *c,
ChainContextApplyLookupContext &lookup_context) const
{
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
return chain_context_would_apply_lookup (c,
backtrack.len, backtrack.arrayZ,
input.lenP1, input.arrayZ,
@ -2777,9 +2777,9 @@ struct ChainRule
bool apply (hb_ot_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const
{
TRACE_APPLY (this);
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
return_trace (chain_context_apply_lookup (c,
backtrack.len, backtrack.arrayZ,
input.lenP1, input.arrayZ,
@ -2812,22 +2812,22 @@ struct ChainRule
serialize_array (c, backtrack.len, + backtrack.iter ()
| hb_map (mapping));
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (input_map) mapping = input_map;
serialize_array (c, input.lenP1, + input.iter ()
| hb_map (mapping));
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (lookahead_map) mapping = lookahead_map;
serialize_array (c, lookahead.len, + lookahead.iter ()
| hb_map (mapping));
const auto &lookupRecord = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
HBUINT16* lookupCount = c->embed (&(lookupRecord.len));
HBUINT16* lookupCount = c->embed (&(lookup.len));
if (!lookupCount) return_trace (false);
unsigned count = serialize_lookuprecord_array (c, lookupRecord.as_array (), lookup_map);
unsigned count = serialize_lookuprecord_array (c, lookup.as_array (), lookup_map);
return_trace (c->check_assign (*lookupCount, count, HB_SERIALIZE_ERROR_INT_OVERFLOW));
}
@ -2839,8 +2839,8 @@ struct ChainRule
{
TRACE_SUBSET (this);
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (!backtrack_map)
{
@ -2869,11 +2869,11 @@ struct ChainRule
{
TRACE_SANITIZE (this);
if (!backtrack.sanitize (c)) return_trace (false);
const auto &input = StructAfter<HeadlessArrayOf<HBUINT16>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!input.sanitize (c)) return_trace (false);
const auto &lookahead = StructAfter<Array16Of<HBUINT16>> (input);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (!lookahead.sanitize (c)) return_trace (false);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
return_trace (lookup.sanitize (c));
}
@ -3467,12 +3467,12 @@ struct ChainContextFormat3
{
bool intersects (const hb_set_t *glyphs) const
{
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!(this+input[0]).intersects (glyphs))
return false;
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
struct ChainContextClosureLookupContext lookup_context = {
{intersects_coverage, intersected_coverage_glyphs},
ContextFormat::CoverageBasedContext,
@ -3490,7 +3490,7 @@ struct ChainContextFormat3
void closure (hb_closure_context_t *c) const
{
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!(this+input[0]).intersects (c->glyphs))
return;
@ -3500,8 +3500,8 @@ struct ChainContextFormat3
cur_active_glyphs);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
struct ChainContextClosureLookupContext lookup_context = {
{intersects_coverage, intersected_coverage_glyphs},
ContextFormat::CoverageBasedContext,
@ -3522,9 +3522,9 @@ struct ChainContextFormat3
if (!intersects (c->glyphs))
return;
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
recurse_lookups (c, lookup.len, lookup.arrayZ);
}
@ -3532,12 +3532,13 @@ struct ChainContextFormat3
void collect_glyphs (hb_collect_glyphs_context_t *c) const
{
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
(this+input[0]).collect_coverage (c->input);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
struct ChainContextCollectGlyphsLookupContext lookup_context = {
{collect_coverage},
{this, this, this}
@ -3552,9 +3553,9 @@ struct ChainContextFormat3
bool would_apply (hb_would_apply_context_t *c) const
{
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
struct ChainContextApplyLookupContext lookup_context = {
{{match_coverage, match_coverage, match_coverage}},
{this, this, this}
@ -3568,20 +3569,20 @@ struct ChainContextFormat3
const Coverage &get_coverage () const
{
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
return this+input[0];
}
bool apply (hb_ot_apply_context_t *c) const
{
TRACE_APPLY (this);
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint);
if (likely (index == NOT_COVERED)) return_trace (false);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
struct ChainContextApplyLookupContext lookup_context = {
{{match_coverage, match_coverage, match_coverage}},
{this, this, this}
@ -3623,21 +3624,21 @@ struct ChainContextFormat3
if (!serialize_coverage_offsets (c, backtrack.iter (), this))
return_trace (false);
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!serialize_coverage_offsets (c, input.iter (), this))
return_trace (false);
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (!serialize_coverage_offsets (c, lookahead.iter (), this))
return_trace (false);
const auto &lookupRecord = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups;
HBUINT16 *lookupCount = c->serializer->copy<HBUINT16> (lookupRecord.len);
HBUINT16 *lookupCount = c->serializer->copy<HBUINT16> (lookup.len);
if (!lookupCount) return_trace (false);
unsigned count = serialize_lookuprecord_array (c->serializer, lookupRecord.as_array (), lookup_map);
unsigned count = serialize_lookuprecord_array (c->serializer, lookup.as_array (), lookup_map);
return_trace (c->serializer->check_assign (*lookupCount, count, HB_SERIALIZE_ERROR_INT_OVERFLOW));
}
@ -3645,12 +3646,12 @@ struct ChainContextFormat3
{
TRACE_SANITIZE (this);
if (!backtrack.sanitize (c, this)) return_trace (false);
const auto &input = StructAfter<Array16OfOffset16To<Coverage>> (backtrack);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!input.sanitize (c, this)) return_trace (false);
if (!input.len) return_trace (false); /* To be consistent with Context. */
const auto &lookahead = StructAfter<Array16OfOffset16To<Coverage>> (input);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (!lookahead.sanitize (c, this)) return_trace (false);
const auto &lookup = StructAfter<Array16Of<LookupRecord>> (lookahead);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
return_trace (lookup.sanitize (c));
}