From 8e5bc535d10fb166f721520db6977cc4e949f1c5 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Wed, 15 Jul 2020 18:54:52 -0700 Subject: [PATCH] [subset] call collect_mapping only when --gids option is used. collect_mapping is time consuming as it iterates all codepoints in all cmap subtables, only trigger it when necessary --- src/hb-ot-cmap-table.hh | 11 +++++++---- src/hb-ot-os2-table.hh | 39 ++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c42f3fd63..4ed9cdf46 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1360,13 +1360,13 @@ struct cmap for (const EncodingRecord& _ : encodingrec_iter) { - hb_set_t unicodes_set; - hb_map_t cp_glyphid_map; - (base+_.subtable).collect_mapping (&unicodes_set, &cp_glyphid_map); - unsigned format = (base+_.subtable).u.format; if (!plan->glyphs_requested->is_empty ()) { + hb_set_t unicodes_set; + hb_map_t cp_glyphid_map; + (base+_.subtable).collect_mapping (&unicodes_set, &cp_glyphid_map); + auto table_iter = + hb_zip (unicodes_set.iter(), unicodes_set.iter() | hb_map(cp_glyphid_map)) | hb_filter (plan->_glyphset, hb_second) @@ -1389,6 +1389,9 @@ struct cmap * all codepoints in each subtable, which is more efficient */ else { + hb_set_t unicodes_set; + (base+_.subtable).collect_unicodes (&unicodes_set); + if (format == 4) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 4u, base, plan, &format4objidx); else if (format == 12) c->copy (_, + it | hb_filter (unicodes_set, hb_first), 12u, base, plan, &format12objidx); else if (format == 14) c->copy (_, it, 14u, base, plan, &format14objidx); diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index f538fd4c0..7d31b712c 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -174,27 +174,32 @@ struct OS2 if (unlikely (!os2_prime)) return_trace (false); hb_set_t unicodes; - hb_map_t unicode_glyphid_map; - - OT::cmap::accelerator_t cmap; - cmap.init (c->plan->source); - cmap.collect_mapping (&unicodes, &unicode_glyphid_map); - cmap.fini (); - - if (c->plan->unicodes->is_empty ()) unicodes.clear (); - else hb_set_set (&unicodes, c->plan->unicodes); - - + unicode_glyphid_map.iter () - | hb_filter (c->plan->glyphs_requested, hb_second) - | hb_map (hb_first) - | hb_sink (unicodes) - ; + if (!c->plan->glyphs_requested->is_empty ()) + { + hb_map_t unicode_glyphid_map; + + OT::cmap::accelerator_t cmap; + cmap.init (c->plan->source); + cmap.collect_mapping (&unicodes, &unicode_glyphid_map); + cmap.fini (); + + if (c->plan->unicodes->is_empty ()) unicodes.clear (); + else hb_set_set (&unicodes, c->plan->unicodes); + + + unicode_glyphid_map.iter () + | hb_filter (c->plan->glyphs_requested, hb_second) + | hb_map (hb_first) + | hb_sink (unicodes) + ; + } + /* when --gids option is not used, no need to do collect_mapping that is + * iterating all codepoints in each subtable, which is not efficient */ uint16_t min_cp, max_cp; - find_min_and_max_codepoint (&unicodes, &min_cp, &max_cp); + find_min_and_max_codepoint (unicodes.is_empty () ? c->plan->unicodes : &unicodes, &min_cp, &max_cp); os2_prime->usFirstCharIndex = min_cp; os2_prime->usLastCharIndex = max_cp; - _update_unicode_ranges (&unicodes, os2_prime->ulUnicodeRange); + _update_unicode_ranges (unicodes.is_empty () ? c->plan->unicodes : &unicodes, os2_prime->ulUnicodeRange); return_trace (true); }