[subset/glyf] Use a hashmap instead of vector for SubsetGlyph

Doens't seem to provide any speedup though.
This commit is contained in:
Behdad Esfahbod 2023-06-01 20:52:36 -06:00
parent c6368e014d
commit b908195634

View file

@ -103,7 +103,7 @@ struct glyf
return false; return false;
} }
hb_vector_t<glyf_impl::SubsetGlyph> glyphs; hb_hashmap_t<hb_codepoint_t, glyf_impl::SubsetGlyph> glyphs;
if (!_populate_subset_glyphs (c->plan, font, glyphs)) if (!_populate_subset_glyphs (c->plan, font, glyphs))
{ {
hb_font_destroy (font); hb_font_destroy (font);
@ -129,7 +129,11 @@ struct glyf
padded_offsets.arrayZ[i] = glyphs[i].length (); padded_offsets.arrayZ[i] = glyphs[i].length ();
} }
bool result = glyf_prime->serialize (c->serializer, glyphs.iter (), use_short_loca, c->plan); auto it =
+ hb_range (num_glyphs)
| hb_map (glyphs)
;
bool result = glyf_prime->serialize (c->serializer, it, use_short_loca, c->plan);
if (c->plan->normalized_coords && !c->plan->pinned_at_default) if (c->plan->normalized_coords && !c->plan->pinned_at_default)
_free_compiled_subset_glyphs (glyphs); _free_compiled_subset_glyphs (glyphs);
@ -145,15 +149,15 @@ struct glyf
bool bool
_populate_subset_glyphs (const hb_subset_plan_t *plan, _populate_subset_glyphs (const hb_subset_plan_t *plan,
hb_font_t *font, hb_font_t *font,
hb_vector_t<glyf_impl::SubsetGlyph> &glyphs /* OUT */) const; hb_hashmap_t<hb_codepoint_t, glyf_impl::SubsetGlyph> &glyphs /* OUT */) const;
hb_font_t * hb_font_t *
_create_font_for_instancing (const hb_subset_plan_t *plan) const; _create_font_for_instancing (const hb_subset_plan_t *plan) const;
void _free_compiled_subset_glyphs (hb_vector_t<glyf_impl::SubsetGlyph> &glyphs) const void _free_compiled_subset_glyphs (hb_hashmap_t<hb_codepoint_t, glyf_impl::SubsetGlyph> &glyphs) const
{ {
for (unsigned i = 0; i < glyphs.length; i++) for (auto &glyph : glyphs.values_ref ())
glyphs[i].free_compiled_bytes (); glyph.free_compiled_bytes ();
} }
protected: protected:
@ -428,17 +432,19 @@ struct glyf_accelerator_t
inline bool inline bool
glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan,
hb_font_t *font, hb_font_t *font,
hb_vector_t<glyf_impl::SubsetGlyph>& glyphs /* OUT */) const hb_hashmap_t<hb_codepoint_t, glyf_impl::SubsetGlyph>& glyphs /* OUT */) const
{ {
OT::glyf_accelerator_t glyf (plan->source); OT::glyf_accelerator_t glyf (plan->source);
unsigned num_glyphs = plan->num_output_glyphs (); if (!glyphs.resize (plan->glyph_map->get_population ())) return false;
if (!glyphs.resize (num_glyphs)) return false;
for (auto p : plan->glyph_map->iter ()) for (auto p : plan->glyph_map->iter ())
{ {
hb_codepoint_t old_gid = p.first; hb_codepoint_t old_gid = p.first;
hb_codepoint_t new_gid = p.second; hb_codepoint_t new_gid = p.second;
glyf_impl::SubsetGlyph& subset_glyph = glyphs.arrayZ[new_gid]; glyphs.set (new_gid, glyf_impl::SubsetGlyph ());
glyf_impl::SubsetGlyph* p_subset_glyph = nullptr;
if (unlikely (!glyphs.has (new_gid, &p_subset_glyph))) return false;
glyf_impl::SubsetGlyph& subset_glyph = *p_subset_glyph;
subset_glyph.old_gid = old_gid; subset_glyph.old_gid = old_gid;
if (unlikely (old_gid == 0 && new_gid == 0 && if (unlikely (old_gid == 0 && new_gid == 0 &&