From dc375559fd8aec33b28ea5775f2288250fd7ede7 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 25 Sep 2020 13:08:46 -0700 Subject: [PATCH] [subset] shrink the serialize buffer when pruning empty offsets in ChainContextFormat2. Currently the code reduces the array length, but does not trim back the space allocated in the serializer for those empty offsets. --- src/hb-ot-layout-gsubgpos.hh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index ec5992d1c..cda1f9a5e 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2794,9 +2794,10 @@ struct ChainContextFormat2 if (unlikely (!c->serializer->check_success (!lookahead_klass_map.in_error ()))) return_trace (false); - unsigned non_zero_index = 0, index = 0; + int non_zero_index = -1, index = 0; bool ret = true; const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + auto last_non_zero = c->serializer->snapshot (); for (const OffsetTo& _ : + hb_enumerate (ruleSet) | hb_filter (input_klass_map, hb_first) | hb_map (hb_second)) @@ -2812,19 +2813,20 @@ struct ChainContextFormat2 &backtrack_klass_map, &input_klass_map, &lookahead_klass_map)) + { + last_non_zero = c->serializer->snapshot (); non_zero_index = index; + } index++; } if (!ret) return_trace (ret); - //prune empty trailing ruleSets - --index; - while (index > non_zero_index) - { - out->ruleSet.pop (); - index--; + // prune empty trailing ruleSets + if (index > non_zero_index) { + c->serializer->revert (last_non_zero); + out->ruleSet.len = non_zero_index + 1; } return_trace (bool (out->ruleSet));