From 7e3c96582f3339caa023133f3c5a21b923fdc2f8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 1 Mar 2025 15:08:41 -0700 Subject: [PATCH] [VARC] Reuse parent MultiVarStore cache if coords didn't change Minor optimization; applicable to the test hangul font mostly. --- src/OT/Var/VARC/VARC.cc | 16 ++++++++++++---- src/OT/Var/VARC/VARC.hh | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index 3b9eec4fb..d9b54b983 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -319,11 +319,15 @@ VarComponent::get_path_at (hb_font_t *font, total_transform.scale (font->x_mult ? 1.f / font->x_multf : 0.f, font->y_mult ? 1.f / font->y_multf : 0.f); + bool same_coords = component_coords.length == coords.length && + component_coords.arrayZ == coords.arrayZ; + VARC.get_path_at (font, gid, draw_session, component_coords, total_transform, parent_gid, decycler, edges_left, depth_left - 1, - scratch); + scratch, + same_coords ? cache : nullptr); } #undef PROCESS_TRANSFORM_COMPONENTS @@ -342,7 +346,8 @@ VARC::get_path_at (hb_font_t *font, hb_decycler_t *decycler, signed *edges_left, signed depth_left, - hb_glyf_scratch_t &scratch) const + hb_glyf_scratch_t &scratch, + VarRegionList::cache_t *parent_cache) const { // Don't recurse on the same glyph. unsigned idx = glyph == parent_glyph ? @@ -382,7 +387,9 @@ VARC::get_path_at (hb_font_t *font, hb_ubytes_t record = (this+glyphRecords)[idx]; float static_cache[sizeof (void *) * 16]; - VarRegionList::cache_t *cache = (this+varStore).create_cache (hb_array (static_cache)); + VarRegionList::cache_t *cache = parent_cache ? + parent_cache : + (this+varStore).create_cache (hb_array (static_cache)); transform.scale (font->x_multf, font->y_multf); @@ -393,7 +400,8 @@ VARC::get_path_at (hb_font_t *font, scratch, cache); - (this+varStore).destroy_cache (cache, hb_array (static_cache)); + if (cache != parent_cache) + (this+varStore).destroy_cache (cache, hb_array (static_cache)); return true; } diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 30e54b6bd..e3756bb09 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -101,7 +101,8 @@ struct VARC hb_decycler_t *decycler, signed *edges_left, signed depth_left, - hb_glyf_scratch_t &scratch) const; + hb_glyf_scratch_t &scratch, + VarRegionList::cache_t *parent_cache = nullptr) const; bool get_path (hb_font_t *font,