From e6827ea9da29adb9b286b4bcd1e1bb7cec6368c7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 15 Oct 2026 12:13:07 -0600 Subject: [PATCH] [subset] Share delta substitution subset serialization SingleSubstFormat1_3 constructs equivalent remapping iterators in each source-format specialization, giving the output and coverage serializers distinct iterator types and duplicating their bodies. Move the subset preparation into a common helper taking the decoded coverage, delta, and glyph mask. Preserve the glyph intersection, modular delta calculation, remapping, and serializer failure behavior. With GCC 15.3 on x86-64 without LTO, this removes 11896 bytes of subset code/read-only data at -O3 and 5776 bytes at -Os. Validated with the full Meson suite (292 passed, one skipped) and subset benchmarks. Assisted-by: OpenAI Codex --- src/OT/Layout/GSUB/SingleSubstFormat1.hh | 50 +++++++++++++----------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index 5cdbb2d68..14d93b809 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -7,6 +7,33 @@ namespace OT { namespace Layout { namespace GSUB_impl { +static inline bool +subset_single_subst (hb_subset_context_t *c, + const Coverage &coverage, + hb_codepoint_t d, + hb_codepoint_t mask) +{ + const hb_set_t &glyphset = *c->plan->glyphset_gsub (); + const hb_map_t &glyph_map = *c->plan->glyph_map; + + hb_set_t intersection; + coverage.intersect_set (glyphset, intersection); + + auto it = + + hb_iter (intersection) + | hb_map_retains_sorting ([d, mask] (hb_codepoint_t g) { + return hb_codepoint_pair_t (g, + (g + d) & mask); }) + | hb_filter (glyphset, hb_second) + | hb_map_retains_sorting ([&] (hb_codepoint_pair_t p) -> hb_codepoint_pair_t + { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) + ; + + bool ret = bool (it); + SingleSubst_serialize (c->serializer, it); + return ret; +} + template struct SingleSubstFormat1_3 { @@ -203,28 +230,7 @@ struct SingleSubstFormat1_3 bool subset (hb_subset_context_t *c) const { TRACE_SUBSET (this); - const hb_set_t &glyphset = *c->plan->glyphset_gsub (); - const hb_map_t &glyph_map = *c->plan->glyph_map; - - hb_codepoint_t d = deltaGlyphID; - hb_codepoint_t mask = get_mask (); - - hb_set_t intersection; - (this+coverage).intersect_set (glyphset, intersection); - - auto it = - + hb_iter (intersection) - | hb_map_retains_sorting ([d, mask] (hb_codepoint_t g) { - return hb_codepoint_pair_t (g, - (g + d) & mask); }) - | hb_filter (glyphset, hb_second) - | hb_map_retains_sorting ([&] (hb_codepoint_pair_t p) -> hb_codepoint_pair_t - { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) - ; - - bool ret = bool (it); - SingleSubst_serialize (c->serializer, it); - return_trace (ret); + return_trace (subset_single_subst (c, this+coverage, deltaGlyphID, get_mask ())); } };