[subset] Cache has_seac in accelerator

Speeds up SourceHanSans-Regular/10000 benchmark by %25.
This commit is contained in:
Behdad Esfahbod 2022-11-21 16:09:39 -07:00
parent dd1ba328a8
commit e0b06bd1b1
4 changed files with 19 additions and 6 deletions

View File

@ -43,10 +43,12 @@ struct hb_subset_accelerator_t
} }
static hb_subset_accelerator_t* create(const hb_map_t& unicode_to_gid_, static hb_subset_accelerator_t* create(const hb_map_t& unicode_to_gid_,
const hb_set_t& unicodes_) { const hb_set_t& unicodes_,
bool has_seac_) {
hb_subset_accelerator_t* accel = hb_subset_accelerator_t* accel =
(hb_subset_accelerator_t*) hb_malloc (sizeof(hb_subset_accelerator_t)); (hb_subset_accelerator_t*) hb_malloc (sizeof(hb_subset_accelerator_t));
new (accel) hb_subset_accelerator_t (unicode_to_gid_, unicodes_); new (accel) hb_subset_accelerator_t (unicode_to_gid_, unicodes_);
accel->has_seac = has_seac_;
return accel; return accel;
} }
@ -64,6 +66,7 @@ struct hb_subset_accelerator_t
const hb_map_t unicode_to_gid; const hb_map_t unicode_to_gid;
const hb_set_t unicodes; const hb_set_t unicodes;
bool has_seac;
// TODO(garretrieger): cumulative glyf checksum map // TODO(garretrieger): cumulative glyf checksum map
// TODO(garretrieger): sanitized table cache. // TODO(garretrieger): sanitized table cache.

View File

@ -47,7 +47,7 @@ using OT::Layout::GPOS;
typedef hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> script_langsys_map; typedef hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> script_langsys_map;
#ifndef HB_NO_SUBSET_CFF #ifndef HB_NO_SUBSET_CFF
static inline void static inline bool
_add_cff_seac_components (const OT::cff1::accelerator_t &cff, _add_cff_seac_components (const OT::cff1::accelerator_t &cff,
hb_codepoint_t gid, hb_codepoint_t gid,
hb_set_t *gids_to_retain) hb_set_t *gids_to_retain)
@ -57,7 +57,9 @@ _add_cff_seac_components (const OT::cff1::accelerator_t &cff,
{ {
gids_to_retain->add (base_gid); gids_to_retain->add (base_gid);
gids_to_retain->add (accent_gid); gids_to_retain->add (accent_gid);
return true;
} }
return false;
} }
#endif #endif
@ -639,9 +641,15 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
else else
plan->_glyphset->union_ (cur_glyphset); plan->_glyphset->union_ (cur_glyphset);
#ifndef HB_NO_SUBSET_CFF #ifndef HB_NO_SUBSET_CFF
if (!plan->accelerator || plan->accelerator->has_seac)
{
bool has_seac = false;
if (cff.is_valid ()) if (cff.is_valid ())
for (hb_codepoint_t gid : cur_glyphset) for (hb_codepoint_t gid : cur_glyphset)
_add_cff_seac_components (cff, gid, plan->_glyphset); if (_add_cff_seac_components (cff, gid, plan->_glyphset))
has_seac = true;
plan->has_seac = has_seac;
}
#endif #endif
_remove_invalid_gids (plan->_glyphset, plan->source->get_num_glyphs ()); _remove_invalid_gids (plan->_glyphset, plan->source->get_num_glyphs ());

View File

@ -194,6 +194,7 @@ struct hb_subset_plan_t
hb_map_t *axes_old_index_tag_map; hb_map_t *axes_old_index_tag_map;
bool all_axes_pinned; bool all_axes_pinned;
bool pinned_at_default; bool pinned_at_default;
bool has_seac;
//hmtx metrics map: new gid->(advance, lsb) //hmtx metrics map: new gid->(advance, lsb)
hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *hmtx_map; hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *hmtx_map;

View File

@ -504,7 +504,8 @@ static void _attach_accelerator_data (const hb_subset_plan_t* plan,
{ {
hb_subset_accelerator_t* accel = hb_subset_accelerator_t* accel =
hb_subset_accelerator_t::create (*plan->codepoint_to_glyph, hb_subset_accelerator_t::create (*plan->codepoint_to_glyph,
*plan->unicodes); *plan->unicodes,
plan->has_seac);
if (accel->in_error ()) if (accel->in_error ())
{ {