[subset] Share PairSet value traversal across glyph widths

Expose the source glyphs, values, count, stride, and device-offset
base through a native view. Share effective-format analysis and
variation-index collection without changing typed glyph emission.
Move the value-copy context out of the source-width template too.

Retain the outer scan guard for variable-device instancing and the
existing record-serialization error behavior.

Saves 1576 bytes at -O3 and 128 bytes at -Os with GCC 15.3 without
LTO. The full Meson suite passes and 288 synthetic narrow/wide subset
cases match baseline table bytes. Sampled CPU-time geometric means
change by -1.08% with hint stripping and -0.23% for font instancing.

Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Behdad Esfahbod committed 2026-10-15 14:45:30 -06:00
1 parent 01e3e76ac8
commit a140b5dc1e
3 files changed
+86 -46

No files matched your search

+4 -14
View File
@@ -241,8 +241,6 @@ struct PairPosFormat1_3
bool strip_hints, bool strip_empty,
const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *varidx_delta_map = nullptr) const
{
unsigned record_size = PairSet::get_size (valueFormat);
unsigned format1 = 0;
unsigned format2 = 0;
for (const auto & _ :
@@ -252,18 +250,10 @@ struct PairPosFormat1_3
)
{
const PairSet& set = (this + _);
const PairValueRecord *record = &set.firstPairValueRecord;
unsigned count = set.len;
for (unsigned i = 0; i < count; i++)
{
if (record->intersects (glyphset))
{
format1 = format1 | valueFormat[0].get_effective_format (record->get_values_1 (), strip_hints, strip_empty, &set, varidx_delta_map);
format2 = format2 | valueFormat[1].get_effective_format (record->get_values_2 (valueFormat[0]), strip_hints, strip_empty, &set, varidx_delta_map);
}
record = &StructAtOffset<const PairValueRecord> (record, record_size);
}
auto formats = set.get_values_view (valueFormat).compute_effective_value_formats (
glyphset, valueFormat, strip_hints, strip_empty, varidx_delta_map);
format1 |= formats.first;
format2 |= formats.second;
if (!varidx_delta_map &&
format1 == valueFormat[0] && format2 == valueFormat[1])
+62 -12
View File
@@ -8,6 +8,60 @@ namespace Layout {
namespace GPOS_impl {
/* Pair records vary in glyph width; their value traversal need not. */
struct pair_set_values_t
{
const ValueBase *base;
glyph_data_t glyphs;
const Value *values;
unsigned count;
unsigned record_size;
unsigned get_glyph (unsigned i) const
{
glyph_data_t glyph = glyphs;
glyph.data = (const char *) glyph.data + i * record_size;
return glyph[0];
}
const Value *get_values (unsigned i) const
{ return reinterpret_cast<const Value *> ((const char *) values + i * record_size); }
hb_pair_t<unsigned, unsigned>
compute_effective_value_formats (const hb_set_t &glyphset,
const ValueFormat valueFormats[2],
bool strip_hints, bool strip_empty,
const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *varidx_delta_map) const
{
unsigned len1 = valueFormats[0].get_len ();
unsigned format1 = 0, format2 = 0;
for (unsigned i = 0; i < count; i++)
{
if (!glyphset.has (get_glyph (i))) continue;
const Value *v = get_values (i);
format1 |= valueFormats[0].get_effective_format (v, strip_hints, strip_empty, base, varidx_delta_map);
format2 |= valueFormats[1].get_effective_format (v + len1, strip_hints, strip_empty, base, varidx_delta_map);
}
return hb_pair (format1, format2);
}
void collect_variation_indices (hb_collect_variation_indices_context_t *c,
const ValueFormat valueFormats[2]) const
{
unsigned len1 = valueFormats[0].get_len ();
unsigned len2 = valueFormats[1].get_len ();
for (unsigned i = 0; i < count; i++)
{
if (!c->glyph_set->has (get_glyph (i))) continue;
const hb_array_t<const Value> v = hb_array (get_values (i), len1 + len2);
if (valueFormats[0].has_device ())
valueFormats[0].collect_variation_indices (c, base, v.sub_array (0, len1));
if (valueFormats[1].has_device ())
valueFormats[1].collect_variation_indices (c, base, v.sub_array (len1, len2));
}
}
};
template <typename Types>
struct PairSet : ValueBase
{
@@ -94,20 +148,16 @@ struct PairSet : ValueBase
glyphs->add_array (&record->secondGlyph, len, record_size);
}
pair_set_values_t get_values_view (const ValueFormat valueFormats[2]) const
{
return {this, &firstPairValueRecord.secondGlyph, &firstPairValueRecord.values[0],
(unsigned) len, (unsigned) get_size (valueFormats)};
}
void collect_variation_indices (hb_collect_variation_indices_context_t *c,
const ValueFormat *valueFormats) const
{
unsigned record_size = get_size (valueFormats);
const PairValueRecord *record = &firstPairValueRecord;
unsigned count = (unsigned) len;
for (unsigned i = 0; i < count; i++)
{
if (c->glyph_set->has (record->secondGlyph))
{ record->collect_variation_indices (c, valueFormats, this); }
record = &StructAtOffset<const PairValueRecord> (record, record_size);
}
get_values_view (valueFormats).collect_variation_indices (c, valueFormats);
}
bool apply (hb_ot_apply_context_t *c,
@@ -190,7 +240,7 @@ struct PairSet : ValueBase
unsigned len2 = valueFormats[1].get_len ();
unsigned record_size = get_size (len1, len2);
typename PairValueRecord::context_t context =
pair_value_record_context_t context =
{
this,
valueFormats,
+20 -20
View File
@@ -8,6 +8,24 @@ namespace Layout {
namespace GPOS_impl {
struct pair_value_record_context_t
{
const ValueBase *base;
const ValueFormat *valueFormats;
const ValueFormat *newFormats;
unsigned len1; /* valueFormats[0].get_len() */
const hb_map_t *glyph_map;
const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map;
void copy_values (hb_serialize_context_t *s, const Value *values) const
{
valueFormats[0].copy_values (s, newFormats[0], base, values,
layout_variation_idx_delta_map);
valueFormats[1].copy_values (s, newFormats[1], base, values + len1,
layout_variation_idx_delta_map);
}
};
template <typename Types>
struct PairValueRecord
{
@@ -27,18 +45,8 @@ struct PairValueRecord
int cmp (hb_codepoint_t k) const
{ return secondGlyph.cmp (k); }
struct context_t
{
const ValueBase *base;
const ValueFormat *valueFormats;
const ValueFormat *newFormats;
unsigned len1; /* valueFormats[0].get_len() */
const hb_map_t *glyph_map;
const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map;
};
bool subset (hb_subset_context_t *c,
context_t *closure) const
pair_value_record_context_t *closure) const
{
TRACE_SERIALIZE (this);
auto *s = c->serializer;
@@ -47,15 +55,7 @@ struct PairValueRecord
out->secondGlyph = (*closure->glyph_map)[secondGlyph];
closure->valueFormats[0].copy_values (s,
closure->newFormats[0],
closure->base, &values[0],
closure->layout_variation_idx_delta_map);
closure->valueFormats[1].copy_values (s,
closure->newFormats[1],
closure->base,
&values[closure->len1],
closure->layout_variation_idx_delta_map);
closure->copy_values (s, values);
return_trace (true);
}