[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 <codex@openai.com>
This commit is contained in:
Behdad Esfahbod committed 2026-10-15 12:13:07 -06:00
1 parent dafbe9c4bb
commit e6827ea9da
1 file changed
+28 -22
+28 -22
View File
@@ -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 <typename Types>
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 ()));
}
};