From 1a00ab69ec012e296f9ec11a9c5619d637012b3b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Jan 2023 10:56:16 -0700 Subject: [PATCH] [subset-plan] Simplify gsub_lookups and gpos_lookups allocation --- src/hb-ot-layout-common.hh | 4 ++-- src/hb-ot-layout-gsubgpos.hh | 12 ++++++------ src/hb-subset-plan.cc | 8 +++----- src/hb-subset-plan.hh | 6 ++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 71eb1821e..71fd2050c 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -156,7 +156,7 @@ struct hb_subset_layout_context_t : { if (tag_ == HB_OT_TAG_GSUB) { - lookup_index_map = c_->plan->gsub_lookups; + lookup_index_map = &c_->plan->gsub_lookups; script_langsys_map = c_->plan->gsub_langsys; feature_index_map = &c_->plan->gsub_features; feature_substitutes_map = c_->plan->gsub_feature_substitutes_map; @@ -164,7 +164,7 @@ struct hb_subset_layout_context_t : } else { - lookup_index_map = c_->plan->gpos_lookups; + lookup_index_map = &c_->plan->gpos_lookups; script_langsys_map = c_->plan->gpos_langsys; feature_index_map = &c_->plan->gpos_features; feature_substitutes_map = c_->plan->gpos_feature_substitutes_map; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 44137844f..9bcdc9c77 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2223,7 +2223,7 @@ struct ContextFormat1_4 if (unlikely (!c->serializer->extend_min (out))) return_trace (false); out->format = format; - const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? &c->plan->gsub_lookups : &c->plan->gpos_lookups; hb_sorted_vector_t new_coverage; + hb_zip (this+coverage, ruleSet) | hb_filter (glyphset, hb_first) @@ -2460,7 +2460,7 @@ struct ContextFormat2_5 hb_set_t coverage_glyph_classes; (this+classDef).intersected_classes (&retained_coverage_glyphs, &coverage_glyph_classes); - const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? &c->plan->gsub_lookups : &c->plan->gpos_lookups; bool ret = true; int non_zero_index = -1, index = 0; auto snapshot = c->serializer->snapshot(); @@ -2640,7 +2640,7 @@ struct ContextFormat3 } const auto& lookupRecord = StructAfter> (coverageZ.as_array (glyphCount)); - const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? &c->plan->gsub_lookups : &c->plan->gpos_lookups; unsigned count = serialize_lookuprecord_array (c->serializer, lookupRecord.as_array (lookupCount), lookup_map); @@ -3304,7 +3304,7 @@ struct ChainContextFormat1_4 if (unlikely (!c->serializer->extend_min (out))) return_trace (false); out->format = format; - const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? &c->plan->gsub_lookups : &c->plan->gpos_lookups; hb_sorted_vector_t new_coverage; + hb_zip (this+coverage, ruleSet) | hb_filter (glyphset, hb_first) @@ -3584,7 +3584,7 @@ struct ChainContextFormat2_5 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; + 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 auto& _ : + hb_enumerate (ruleSet) | hb_filter (input_klass_map, hb_first)) @@ -3826,7 +3826,7 @@ struct ChainContextFormat3 return_trace (false); const auto &lookup = StructAfter (lookahead); - const hb_map_t *lookup_map = c->table_tag == HB_OT_TAG_GSUB ? c->plan->gsub_lookups : c->plan->gpos_lookups; + 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 (lookup.len); if (!lookupCount) return_trace (false); diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 895188f7e..1d09983ec 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -383,7 +383,7 @@ _collect_layout_variation_indices (hb_subset_plan_t* plan) plan->layout_variation_idx_delta_map, font, var_store, plan->_glyphset_gsub, - plan->gpos_lookups, + &plan->gpos_lookups, store_cache); gdef->collect_variation_indices (&c); @@ -629,7 +629,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, _closure_glyphs_lookups_features ( plan, plan->_glyphset_gsub, - plan->gsub_lookups, + &plan->gsub_lookups, &plan->gsub_features, plan->gsub_langsys, plan->gsub_feature_record_cond_idx_map, @@ -639,7 +639,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, _closure_glyphs_lookups_features ( plan, plan->_glyphset_gsub, - plan->gpos_lookups, + &plan->gpos_lookups, &plan->gpos_features, plan->gpos_langsys, plan->gpos_feature_record_cond_idx_map, @@ -860,8 +860,6 @@ hb_subset_plan_create_or_fail (hb_face_t *face, plan->glyph_map = hb_map_create (); plan->reverse_glyph_map = hb_map_create (); plan->glyph_map_gsub = hb_map_create (); - plan->gsub_lookups = hb_map_create (); - plan->gpos_lookups = hb_map_create (); plan->check_success (plan->gsub_langsys = hb_hashmap_create> ()); plan->check_success (plan->gpos_langsys = hb_hashmap_create> ()); diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 48b2f9178..432a4714d 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -62,8 +62,6 @@ struct hb_subset_plan_t hb_set_destroy (_glyphset_gsub); hb_set_destroy (_glyphset_mathed); hb_set_destroy (_glyphset_colred); - hb_map_destroy (gsub_lookups); - hb_map_destroy (gpos_lookups); hb_map_destroy (colrv1_layers); hb_map_destroy (colr_palettes); hb_map_destroy (axes_index_map); @@ -151,8 +149,8 @@ struct hb_subset_plan_t hb_set_t *_glyphset_colred; //active lookups we'd like to retain - hb_map_t *gsub_lookups; - hb_map_t *gpos_lookups; + hb_map_t gsub_lookups; + hb_map_t gpos_lookups; //active langsys we'd like to retain hb_hashmap_t> *gsub_langsys;