From 318aa107082cf4ab1c2fcc5f0bf2ead145216e1d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 29 Jan 2023 09:17:17 -0500 Subject: [PATCH] [ot-font] Use the cmap cache more Use the cmap cache for get_nominal_glyph and get_variation_glyph as well. The first of these is used a lot in pango. --- src/hb-ot-cmap-table.hh | 21 +++++++++++++++------ src/hb-ot-font.cc | 6 ++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c4a09874d..3c6c87fc0 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1896,9 +1896,8 @@ struct cmap ~accelerator_t () { this->table.destroy (); } bool get_nominal_glyph (hb_codepoint_t unicode, - hb_codepoint_t *glyph) const + hb_codepoint_t *glyph) const { - if (unlikely (!this->get_glyph_funcZ)) return false; return this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph); } @@ -1913,12 +1912,20 @@ struct cmap *glyph = v; return true; } - bool ret = this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph); + bool ret = get_nominal_glyph (unicode, glyph); if (cache && ret) - cache->set (unicode, *glyph); + cache->set (unicode, *glyph); return ret; } + template + bool get_nominal_glyph (hb_codepoint_t unicode, + hb_codepoint_t *glyph, + cache_t *cache = nullptr) const + { + return _cached_get (unicode, glyph, cache); + } + template unsigned int get_nominal_glyphs (unsigned int count, const hb_codepoint_t *first_unicode, @@ -1940,9 +1947,11 @@ struct cmap return done; } + template bool get_variation_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, - hb_codepoint_t *glyph) const + hb_codepoint_t *glyph, + cache_t *cache = nullptr) const { switch (this->subtable_uvs->get_glyph_variant (unicode, variation_selector, @@ -1953,7 +1962,7 @@ struct cmap case GLYPH_VARIANT_USE_DEFAULT: break; } - return get_nominal_glyph (unicode, glyph); + return get_nominal_glyph (unicode, glyph, cache); } void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index e03339d85..42f314371 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -136,7 +136,7 @@ hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED, { const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_face_t *ot_face = ot_font->ot_face; - return ot_face->cmap->get_nominal_glyph (unicode, glyph); + return ot_face->cmap->get_nominal_glyph (unicode, glyph, ot_font->cmap_cache); } static unsigned int @@ -167,7 +167,9 @@ hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED, { const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_face_t *ot_face = ot_font->ot_face; - return ot_face->cmap->get_variation_glyph (unicode, variation_selector, glyph); + return ot_face->cmap->get_variation_glyph (unicode, + variation_selector, glyph, + ot_font->cmap_cache); } static void