[subset/retaingid] Regain perf lost

In 0f12fd5a66
pull/4264/head
Behdad Esfahbod 1 year ago
parent 0f12fd5a66
commit b67e464b1c
  1. 20
      src/OT/glyf/glyf.hh
  2. 14
      src/hb-ot-hmtx-table.hh
  3. 2
      src/hb-subset-plan-member-list.hh
  4. 10
      src/hb-subset-plan.cc

@ -116,14 +116,10 @@ struct glyf
auto new_to_old_gid_list = c->plan->new_to_old_gid_list;
unsigned max_offset = 0;
auto it = c->plan->glyphset ()->iter ();
for (unsigned i = 0, j = 0; i < num_glyphs; i++)
{
if (new_to_old_gid_list[i] == *it)
{
if (i == new_to_old_gid_list[j].first)
padded_offsets.arrayZ[i] = glyphs[j++].padded_size ();
it++;
}
else
padded_offsets.arrayZ[i] = 0;
max_offset += padded_offsets[i];
@ -135,13 +131,9 @@ struct glyf
if (!use_short_loca)
{
auto it = c->plan->glyphset ()->iter ();
for (unsigned i = 0, j = 0; i < num_glyphs; i++)
if (new_to_old_gid_list[i] == *it)
{
if (i == new_to_old_gid_list[j].first)
padded_offsets.arrayZ[i] = glyphs[j++].length ();
it++;
}
else
padded_offsets.arrayZ[i] = 0;
}
@ -450,15 +442,15 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan,
OT::glyf_accelerator_t glyf (plan->source);
if (!glyphs.alloc (plan->glyph_map->get_population (), true)) return false;
for (hb_codepoint_t old_gid : plan->new_to_old_gid_list)
for (const auto &pair : plan->new_to_old_gid_list)
{
if (old_gid == HB_MAP_VALUE_INVALID)
continue;
hb_codepoint_t new_gid = pair.first;
hb_codepoint_t old_gid = pair.second;
glyf_impl::SubsetGlyph *p = glyphs.push ();
glyf_impl::SubsetGlyph& subset_glyph = *p;
subset_glyph.old_gid = old_gid;
if (unlikely (old_gid == 0 &&
if (unlikely (old_gid == 0 && new_gid == 0 &&
!(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) &&
!plan->normalized_coords)
subset_glyph.source_glyph = glyf_impl::Glyph ();

@ -204,14 +204,16 @@ struct hmtxvmtx
}
}
unsigned j = 0;
const auto &new_to_old_gid_list = c->plan->new_to_old_gid_list;
auto it =
+ hb_enumerate (c->plan->new_to_old_gid_list)
| hb_map ([c, &_mtx, mtx_map] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> &_)
+ hb_range (c->plan->num_output_glyphs ())
| hb_map ([c, &j, &new_to_old_gid_list, &_mtx, mtx_map] (hb_codepoint_t new_gid)
{
hb_codepoint_t new_gid = _.first;
hb_codepoint_t old_gid = _.second;
if (old_gid == HB_MAP_VALUE_INVALID)
if (new_gid != new_to_old_gid_list[j].first)
return hb_pair (0u, 0);
unsigned old_gid = new_to_old_gid_list[j].second;
j++;
hb_pair_t<unsigned, int> *v = nullptr;
if (!mtx_map->has (new_gid, &v))
@ -225,7 +227,7 @@ struct hmtxvmtx
})
;
table_prime->serialize (c->serializer, it, num_long_metrics, c->plan->new_to_old_gid_list.length);
table_prime->serialize (c->serializer, it, num_long_metrics, c->plan->num_output_glyphs ());
if (unlikely (c->serializer->in_error ()))
return_trace (false);

@ -35,7 +35,7 @@
HB_SUBSET_PLAN_MEMBER (hb_set_t, unicodes)
HB_SUBSET_PLAN_MEMBER (hb_sorted_vector_t E(<hb_pair_t<hb_codepoint_t, hb_codepoint_t>>), unicode_to_new_gid_list)
HB_SUBSET_PLAN_MEMBER (hb_vector_t<hb_codepoint_t>, new_to_old_gid_list)
HB_SUBSET_PLAN_MEMBER (hb_sorted_vector_t E(<hb_pair_t<hb_codepoint_t, hb_codepoint_t>>), new_to_old_gid_list)
// name_ids we would like to retain
HB_SUBSET_PLAN_MEMBER (hb_set_t, name_ids)

@ -782,7 +782,7 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face,
const hb_map_t *requested_glyph_map,
hb_map_t *glyph_map, /* OUT */
hb_map_t *reverse_glyph_map, /* OUT */
hb_vector_t<hb_codepoint_t> *new_to_old_gid_list /* OUT */,
hb_sorted_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> *new_to_old_gid_list /* OUT */,
unsigned int *num_glyphs /* OUT */)
{
unsigned pop = all_gids_to_retain->get_population ();
@ -863,11 +863,9 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face,
| hb_sink (glyph_map)
;
auto &l = *new_to_old_gid_list;
l.resize (*num_glyphs);
hb_memset (l.arrayZ, 0xff, l.length * sizeof (l[0]));
for (auto _ : *reverse_glyph_map)
l[_.first] = _.second;
new_to_old_gid_list->alloc (reverse_glyph_map->get_population ());
hb_copy (*reverse_glyph_map, *new_to_old_gid_list);
new_to_old_gid_list->qsort ();
return true;
}

Loading…
Cancel
Save