From 5e3cbed048b19ee579277ab4c56167a15d13104e Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 8 May 2019 16:33:03 -0700 Subject: [PATCH] [subset] Switch building of glyph maps in subset plan to use iterators. --- src/hb-algs.hh | 4 +--- src/hb-subset-plan.cc | 52 +++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index ca7075538..dbb0805fc 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -218,9 +218,7 @@ struct hb_pair_t hb_pair_t (const pair_t& o) : first (o.first), second (o.second) {} hb_pair_t reverse () const - { - return hb_pair_t (second, first); - } + { return hb_pair_t (second, first); } bool operator == (const pair_t& o) const { return first == o.first && second == o.second; } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 901347b9f..66976fa95 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -153,36 +153,36 @@ _populate_gids_to_retain (hb_face_t *face, } static void -_create_old_gid_to_new_gid_map (const hb_face_t *face, - bool retain_gids, - hb_set_t *all_gids_to_retain, - hb_map_t *glyph_map, /* OUT */ - hb_map_t *reverse_glyph_map, /* OUT */ - unsigned int *num_glyphs /* OUT */) +_create_old_gid_to_new_gid_map (const hb_face_t *face, + bool retain_gids, + const hb_set_t *all_gids_to_retain, + hb_map_t *glyph_map, /* OUT */ + hb_map_t *reverse_glyph_map, /* OUT */ + unsigned int *num_glyphs /* OUT */) { - hb_codepoint_t gid = HB_SET_VALUE_INVALID; - unsigned int length = 0; - for (unsigned int i = 0; all_gids_to_retain->next (&gid); i++) { - if (!retain_gids) - { - glyph_map->set (gid, i); - reverse_glyph_map->set (i, gid); - } - else - { - glyph_map->set (gid, gid); - reverse_glyph_map->set (gid, gid); - } - ++length; - } - if (!retain_gids || length == 0) - { - *num_glyphs = length; - } - else + if (!retain_gids) { + + hb_enumerate (hb_iter (all_gids_to_retain), (hb_codepoint_t) 0) + | hb_sink (reverse_glyph_map) + ; + *num_glyphs = reverse_glyph_map->get_population (); + } else { + + hb_iter (all_gids_to_retain) + | hb_map ([=] (hb_codepoint_t _) { + return hb_pair_t (_, _); + }) + | hb_sink (reverse_glyph_map); + ; + + // TODO(grieger): Should we discard glyphs past the max glyph to keep? + // *num_glyphs = + hb_iter (all_gids_to_retain) | hb_reduce (hb_max, 0); *num_glyphs = face->get_num_glyphs (); } + + + reverse_glyph_map->iter () + | hb_map (&hb_pair_t::reverse) + | hb_sink (glyph_map) + ; } /**