From b67e464b1cefb733df073590588ab8fcca320bfc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 2 Jun 2023 15:11:06 -0600 Subject: [PATCH] [subset/retaingid] Regain perf lost In 0f12fd5a66a5dd1c3c9ac5ea8a52341bafcfe567 --- src/OT/glyf/glyf.hh | 20 ++++++-------------- src/hb-ot-hmtx-table.hh | 14 ++++++++------ src/hb-subset-plan-member-list.hh | 2 +- src/hb-subset-plan.cc | 10 ++++------ 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 03b23e069..315a42eb8 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -116,14 +116,10 @@ struct glyf auto new_to_old_gid_list = c->plan->new_to_old_gid_list; unsigned max_offset = 0; - auto it = c->plan->glyphset ()->iter (); for (unsigned i = 0, j = 0; i < num_glyphs; i++) { - if (new_to_old_gid_list[i] == *it) - { + if (i == new_to_old_gid_list[j].first) padded_offsets.arrayZ[i] = glyphs[j++].padded_size (); - it++; - } else padded_offsets.arrayZ[i] = 0; max_offset += padded_offsets[i]; @@ -135,13 +131,9 @@ struct glyf if (!use_short_loca) { - auto it = c->plan->glyphset ()->iter (); for (unsigned i = 0, j = 0; i < num_glyphs; i++) - if (new_to_old_gid_list[i] == *it) - { + if (i == new_to_old_gid_list[j].first) padded_offsets.arrayZ[i] = glyphs[j++].length (); - it++; - } else padded_offsets.arrayZ[i] = 0; } @@ -450,15 +442,15 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, OT::glyf_accelerator_t glyf (plan->source); if (!glyphs.alloc (plan->glyph_map->get_population (), true)) return false; - for (hb_codepoint_t old_gid : plan->new_to_old_gid_list) + for (const auto &pair : plan->new_to_old_gid_list) { - if (old_gid == HB_MAP_VALUE_INVALID) - continue; + hb_codepoint_t new_gid = pair.first; + hb_codepoint_t old_gid = pair.second; glyf_impl::SubsetGlyph *p = glyphs.push (); glyf_impl::SubsetGlyph& subset_glyph = *p; subset_glyph.old_gid = old_gid; - if (unlikely (old_gid == 0 && + if (unlikely (old_gid == 0 && new_gid == 0 && !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) && !plan->normalized_coords) subset_glyph.source_glyph = glyf_impl::Glyph (); diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 877e39494..3686d176c 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -204,14 +204,16 @@ struct hmtxvmtx } } + unsigned j = 0; + const auto &new_to_old_gid_list = c->plan->new_to_old_gid_list; auto it = - + hb_enumerate (c->plan->new_to_old_gid_list) - | hb_map ([c, &_mtx, mtx_map] (const hb_pair_t &_) + + hb_range (c->plan->num_output_glyphs ()) + | hb_map ([c, &j, &new_to_old_gid_list, &_mtx, mtx_map] (hb_codepoint_t new_gid) { - hb_codepoint_t new_gid = _.first; - hb_codepoint_t old_gid = _.second; - if (old_gid == HB_MAP_VALUE_INVALID) + if (new_gid != new_to_old_gid_list[j].first) return hb_pair (0u, 0); + unsigned old_gid = new_to_old_gid_list[j].second; + j++; hb_pair_t *v = nullptr; if (!mtx_map->has (new_gid, &v)) @@ -225,7 +227,7 @@ struct hmtxvmtx }) ; - table_prime->serialize (c->serializer, it, num_long_metrics, c->plan->new_to_old_gid_list.length); + table_prime->serialize (c->serializer, it, num_long_metrics, c->plan->num_output_glyphs ()); if (unlikely (c->serializer->in_error ())) return_trace (false); diff --git a/src/hb-subset-plan-member-list.hh b/src/hb-subset-plan-member-list.hh index 4794f9b5f..a28bfb12a 100644 --- a/src/hb-subset-plan-member-list.hh +++ b/src/hb-subset-plan-member-list.hh @@ -35,7 +35,7 @@ HB_SUBSET_PLAN_MEMBER (hb_set_t, unicodes) HB_SUBSET_PLAN_MEMBER (hb_sorted_vector_t E(>), unicode_to_new_gid_list) -HB_SUBSET_PLAN_MEMBER (hb_vector_t, new_to_old_gid_list) +HB_SUBSET_PLAN_MEMBER (hb_sorted_vector_t E(>), new_to_old_gid_list) // name_ids we would like to retain HB_SUBSET_PLAN_MEMBER (hb_set_t, name_ids) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index b6558e945..54ec360ef 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -782,7 +782,7 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, const hb_map_t *requested_glyph_map, hb_map_t *glyph_map, /* OUT */ hb_map_t *reverse_glyph_map, /* OUT */ - hb_vector_t *new_to_old_gid_list /* OUT */, + hb_sorted_vector_t> *new_to_old_gid_list /* OUT */, unsigned int *num_glyphs /* OUT */) { unsigned pop = all_gids_to_retain->get_population (); @@ -863,11 +863,9 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face, | hb_sink (glyph_map) ; - auto &l = *new_to_old_gid_list; - l.resize (*num_glyphs); - hb_memset (l.arrayZ, 0xff, l.length * sizeof (l[0])); - for (auto _ : *reverse_glyph_map) - l[_.first] = _.second; + new_to_old_gid_list->alloc (reverse_glyph_map->get_population ()); + hb_copy (*reverse_glyph_map, *new_to_old_gid_list); + new_to_old_gid_list->qsort (); return true; }