From ced6e141a7fed91a05e707eecbbc95b13937eebc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 4 Jun 2026 22:59:04 +0200 Subject: [PATCH] [var] Embed gvar accelerator fallbacks The gvar facade only needs to pick between concrete table accelerators. Embed the lowercase and uppercase accelerators directly instead of allocating the selected implementation by hand. This removes the extra allocation failure path and lifetime helpers, while preserving the GVAR-first fallback order. Tested with meson test -C build. Assisted-by: OpenAI Codex --- src/hb-ot-var-gvar-table.hh | 78 ++++++++++--------------------------- 1 file changed, 20 insertions(+), 58 deletions(-) diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 12cff131d..890956c7b 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -1024,40 +1024,18 @@ struct GVAR : gvar_GVAR struct gvar_accelerator_t { gvar_accelerator_t (hb_face_t *face) : - gvar_accel (nullptr) #ifndef HB_NO_BEYOND_64K - , GVAR_accel (nullptr) + GVAR_accel (face, GVAR::tableTag), #endif - { -#ifndef HB_NO_BEYOND_64K - GVAR_accel = create_accelerator (face); - if (GVAR_accel && GVAR_accel->has_data ()) - { - gvar_accel = nullptr; - return; - } - destroy_accelerator (GVAR_accel); - GVAR_accel = nullptr; -#endif - - gvar_accel = create_accelerator (face); - } - - ~gvar_accelerator_t () - { - destroy_accelerator (gvar_accel); -#ifndef HB_NO_BEYOND_64K - destroy_accelerator (GVAR_accel); -#endif - } + gvar_accel (face, gvar::tableTag) + {} hb_scalar_cache_t *create_cache () const { #ifndef HB_NO_BEYOND_64K - if (GVAR_accel) return GVAR_accel->create_cache (); + if (GVAR_accel.has_data ()) return GVAR_accel.create_cache (); #endif - if (unlikely (!gvar_accel)) return nullptr; - return gvar_accel->create_cache (); + return gvar_accel.create_cache (); } static void destroy_cache (hb_scalar_cache_t *cache) @@ -1068,10 +1046,10 @@ struct gvar_accelerator_t bool has_data () const { #ifndef HB_NO_BEYOND_64K - if (GVAR_accel) return GVAR_accel->has_data (); + if (GVAR_accel.has_data ()) return true; #endif - if (unlikely (!gvar_accel)) return false; - return gvar_accel->has_data (); + if (gvar_accel.has_data ()) return true; + return false; } bool apply_deltas_to_points (hb_codepoint_t glyph, @@ -1082,46 +1060,30 @@ struct gvar_accelerator_t bool phantom_only = false) const { #ifndef HB_NO_BEYOND_64K - if (GVAR_accel) - return GVAR_accel->apply_deltas_to_points (glyph, coords, points, scratch, - gvar_cache, phantom_only); + if (GVAR_accel.has_data ()) + return GVAR_accel.apply_deltas_to_points (glyph, coords, points, scratch, + gvar_cache, phantom_only); #endif - if (unlikely (!gvar_accel)) return true; - return gvar_accel->apply_deltas_to_points (glyph, coords, points, scratch, - gvar_cache, phantom_only); + if (gvar_accel.has_data ()) + return gvar_accel.apply_deltas_to_points (glyph, coords, points, scratch, + gvar_cache, phantom_only); + return true; } unsigned int get_axis_count () const { #ifndef HB_NO_BEYOND_64K - if (GVAR_accel) return GVAR_accel->get_axis_count (); + if (GVAR_accel.has_data ()) return GVAR_accel.get_axis_count (); #endif - if (unlikely (!gvar_accel)) return 0; - return gvar_accel->get_axis_count (); + if (gvar_accel.has_data ()) return gvar_accel.get_axis_count (); + return 0; } private: - template - static typename Table::accelerator_t *create_accelerator (hb_face_t *face) - { - typename Table::accelerator_t *accel = - (typename Table::accelerator_t *) hb_calloc (1, sizeof (typename Table::accelerator_t)); - if (unlikely (!accel)) return nullptr; - return new (accel) typename Table::accelerator_t (face, Table::tableTag); - } - - template - static void destroy_accelerator (Accel *accel) - { - if (!accel) return; - accel->~Accel (); - hb_free (accel); - } - - gvar::accelerator_t *gvar_accel; #ifndef HB_NO_BEYOND_64K - GVAR::accelerator_t *GVAR_accel; + GVAR::accelerator_t GVAR_accel; #endif + gvar::accelerator_t gvar_accel; }; } /* namespace OT */