From 24b069cd53cec2d8afa4e7b90cf5b47c91e215c9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 2 Jun 2023 15:55:53 -0600 Subject: [PATCH] [subset] Pre-alloc a few maps --- src/hb-multimap.hh | 5 +++++ src/hb-ot-post-table-v2subset.hh | 12 +++++++++--- src/hb-subset-plan.cc | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hb-multimap.hh b/src/hb-multimap.hh index b4a8cc62a..42d6c8aae 100644 --- a/src/hb-multimap.hh +++ b/src/hb-multimap.hh @@ -81,6 +81,11 @@ struct hb_multimap_t return singulars.in_error () || multiples_indices.in_error () || multiples_values.in_error (); } + void resize (unsigned size) + { + singulars.resize (size); + } + protected: hb_map_t singulars; hb_map_t multiples_indices; diff --git a/src/hb-ot-post-table-v2subset.hh b/src/hb-ot-post-table-v2subset.hh index 951e6395d..c184ad1a5 100644 --- a/src/hb-ot-post-table-v2subset.hh +++ b/src/hb-ot-post-table-v2subset.hh @@ -79,6 +79,11 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const post::accelerator_t _post (c->plan->source); hb_hashmap_t glyph_name_to_new_index; + + old_new_index_map.resize (num_glyphs); + old_gid_new_index_map.resize (num_glyphs); + glyph_name_to_new_index.resize (num_glyphs); + for (hb_codepoint_t new_gid = 0; new_gid < num_glyphs; new_gid++) { hb_codepoint_t old_gid = reverse_glyph_map.get (new_gid); @@ -86,11 +91,12 @@ HB_INTERNAL bool postV2Tail::subset (hb_subset_context_t *c) const unsigned new_index; const uint32_t *new_index2; - if (old_index <= 257) new_index = old_index; + if (old_index <= 257) + new_index = old_index; else if (old_new_index_map.has (old_index, &new_index2)) - { new_index = *new_index2; - } else { + else + { hb_bytes_t s = _post.find_glyph_name (old_gid); new_index = glyph_name_to_new_index.get (s); if (new_index == (unsigned)-1) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 506aba0fc..38ef76da5 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -769,6 +769,7 @@ _create_glyph_map_gsub (const hb_set_t* glyph_set_gsub, const hb_map_t* glyph_map, hb_map_t* out) { + out->resize (glyph_set_gsub->get_population ()); + hb_iter (glyph_set_gsub) | hb_map ([&] (hb_codepoint_t gid) { return hb_pair_t (gid, @@ -1130,6 +1131,7 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face, hb_map_t &unicode_to_gid = *codepoint_to_glyph; + gid_to_unicodes.resize (unicodes.get_population ()); for (auto unicode : unicodes) { auto gid = unicode_to_gid[unicode];