From 882d328839da03c1dff455592eb42776682d2e90 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 25 Feb 2025 16:34:55 -0700 Subject: [PATCH] [glyf] Port to decycler for composite glyphs 5% speed up drawing Roboto-Regular.ttf. --- src/OT/glyf/Glyph.hh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 825c7a5b0..b3aa3b7c0 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -3,6 +3,7 @@ #include "../../hb-open-type.hh" +#include "../../hb-decycler.hh" #include "GlyphHeader.hh" #include "SimpleGlyph.hh" @@ -314,7 +315,7 @@ struct Glyph bool use_my_metrics = true, bool phantom_only = false, hb_array_t coords = hb_array_t (), - hb_map_t *current_glyphs = nullptr, + hb_decycler_t *decycler = nullptr, unsigned int depth = 0, unsigned *edge_count = nullptr) const { @@ -324,10 +325,6 @@ struct Glyph if (unlikely (*edge_count > HB_MAX_GRAPH_EDGE_COUNT)) return false; (*edge_count)++; - hb_map_t current_glyphs_stack; - if (current_glyphs == nullptr) - current_glyphs = ¤t_glyphs_stack; - if (head_maxp_info) { head_maxp_info->maxComponentDepth = hb_max (head_maxp_info->maxComponentDepth, depth); @@ -412,16 +409,20 @@ struct Glyph break; case COMPOSITE: { + hb_decycler_t decycler_stack; // TODO Move out of here + if (!decycler) + decycler = &decycler_stack; + + hb_decycler_node_t decycler_node (*decycler); + unsigned int comp_index = 0; for (auto &item : get_composite_iterator ()) { hb_codepoint_t item_gid = item.get_gid (); - if (unlikely (current_glyphs->has (item_gid))) + if (unlikely (!decycler_node.visit (item_gid))) continue; - current_glyphs->add (item_gid); - unsigned old_count = all_points.length; if (unlikely ((!phantom_only || (use_my_metrics && item.is_use_my_metrics ())) && @@ -437,13 +438,10 @@ struct Glyph use_my_metrics, phantom_only, coords, - current_glyphs, + decycler, depth + 1, edge_count))) - { - current_glyphs->del (item_gid); return false; - } auto comp_points = all_points.as_array ().sub_array (old_count); @@ -479,13 +477,9 @@ struct Glyph all_points.resize (all_points.length - PHANTOM_COUNT); if (all_points.length > HB_GLYF_MAX_POINTS) - { - current_glyphs->del (item_gid); return false; - } comp_index++; - current_glyphs->del (item_gid); } if (head_maxp_info && depth == 0)