From 7cb36e422218305329102849c156ab94db91cbef Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 4 May 2022 21:22:26 +0000 Subject: [PATCH] [subset] Re-introduce size threshold in choosing unicode collection method. Threshold is needed since the unicodes set might be an inverted set. --- src/hb-subset-plan.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 5a9ad71d8..4cff60e54 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -302,10 +302,12 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, { OT::cmap::accelerator_t cmap (plan->source); - if (glyphs->is_empty ()) + unsigned size_threshold = plan->source->get_num_glyphs (); + if (glyphs->is_empty () && unicodes->get_population () < size_threshold) { // This is approach to collection is faster, but can only be used if glyphs - // are not being explicitly added to the subset. + // are not being explicitly added to the subset and the input unicodes set is + // not excessively large (eg. an inverted set). plan->unicode_to_new_gid_list.alloc (unicodes->get_population ()); for (hb_codepoint_t cp : *unicodes) { @@ -326,8 +328,10 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes, // them with cmap entries. hb_map_t unicode_glyphid_map; cmap.collect_mapping (hb_set_get_empty (), &unicode_glyphid_map); - plan->unicode_to_new_gid_list.alloc (unicodes->get_population () - + glyphs->get_population ()); + plan->unicode_to_new_gid_list.alloc (hb_min(unicodes->get_population () + + glyphs->get_population (), + unicode_glyphid_map.get_population ())); + for (hb_pair_t cp_gid : + unicode_glyphid_map.iter ())