From e5a01efd07e540f2202d64dbc9372dc6f1be4a1e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 13 Mar 2025 02:42:43 -0600 Subject: [PATCH] [aat] Put back one set of compiled map in the plan Use it if there's no user features. Reduces mallocs. --- src/hb-aat-layout.cc | 15 +++++++++------ src/hb-ot-shape.cc | 5 +++++ src/hb-ot-shape.hh | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 090e281d2..ea3a6d4b6 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -204,7 +204,7 @@ hb_aat_layout_find_feature_mapping (hb_tag_t tag) #endif -#ifndef HB_NO_AAT +#ifndef HB_NO_AAT_SHAPE /* * mort/morx/kerx/trak @@ -288,11 +288,14 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, const hb_feature_t *features, unsigned num_features) { - hb_aat_map_builder_t builder (font->face, plan->props); - for (unsigned i = 0; i < num_features; i++) - builder.add_feature (features[i]); hb_aat_map_t map; - builder.compile (map); + if (num_features) + { + hb_aat_map_builder_t builder (font->face, plan->props); + for (unsigned i = 0; i < num_features; i++) + builder.add_feature (features[i]); + builder.compile (map); + } { auto &accel = *font->face->table.morx; @@ -301,7 +304,7 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, { AAT::hb_aat_apply_context_t c (plan, font, buffer, accel.get_blob ()); if (!buffer->message (font, "start table morx")) return; - morx.apply (&c, map, accel); + morx.apply (&c, num_features ? map : plan->aat_map, accel); (void) buffer->message (font, "end table morx"); return; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 0469d5981..dfc6be0fb 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -84,6 +84,7 @@ hb_ot_shape_planner_t::hb_ot_shape_planner_t (hb_face_t *fac props (props), map (face, props) #ifndef HB_NO_AAT_SHAPE + , aat_map (face, props) , apply_morx (_hb_apply_morx (face, props)) #endif { @@ -106,6 +107,10 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan, plan.props = props; plan.shaper = shaper; map.compile (plan.map, key); +#ifndef HB_NO_AAT_SHAPE + if (apply_morx) + aat_map.compile (plan.aat_map); +#endif #ifndef HB_NO_OT_SHAPE_FRACTIONS plan.frac_mask = plan.map.get_1_mask (HB_TAG ('f','r','a','c')); diff --git a/src/hb-ot-shape.hh b/src/hb-ot-shape.hh index 791bc6896..493988185 100644 --- a/src/hb-ot-shape.hh +++ b/src/hb-ot-shape.hh @@ -66,6 +66,7 @@ struct hb_ot_shape_plan_t hb_segment_properties_t props; const struct hb_ot_shaper_t *shaper; hb_ot_map_t map; + hb_aat_map_t aat_map; const void *data; #ifndef HB_NO_OT_SHAPE_FRACTIONS hb_mask_t frac_mask, numr_mask, dnom_mask; @@ -141,6 +142,7 @@ struct hb_ot_shape_planner_t hb_segment_properties_t props; hb_ot_map_builder_t map; #ifndef HB_NO_AAT_SHAPE + hb_aat_map_builder_t aat_map; bool apply_morx : 1; #else static constexpr bool apply_morx = false;