[subset-cff1] Cache glyph-to-sid-map in the accelerator

Benchmark                                                                                      Time             CPU      Time Old      Time New       CPU Old       CPU New
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/10                   -0.0841         -0.0843             0             0             0             0
BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/64                   -0.1305         -0.1305             0             0             0             0
BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/512                  -0.1398         -0.1401             1             1             1             1
BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/4096                 +0.0382         +0.0380             9             9             9             9
BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/10000                +0.0213         +0.0211            11            11            11            11
This commit is contained in:
Behdad Esfahbod 2022-11-30 13:15:58 -07:00
parent 72fabef0a4
commit 32dd9810cf
3 changed files with 24 additions and 4 deletions

View File

@ -483,6 +483,11 @@ struct cff2
blob = nullptr;
}
hb_map_t *create_glyph_to_sid_map () const
{
return nullptr;
}
bool is_valid () const { return blob; }
protected:

View File

@ -433,11 +433,13 @@ struct cff_subset_accelerator_t
~cff_subset_accelerator_t() {
hb_blob_destroy (original_blob);
hb_map_destroy (glyph_to_sid_map.get_relaxed ());
}
parsed_cs_str_vec_t parsed_charstrings;
parsed_cs_str_vec_t parsed_global_subrs;
hb_vector_t<parsed_cs_str_vec_t> parsed_local_subrs;
mutable hb_atomic_ptr_t<hb_map_t> glyph_to_sid_map = nullptr;
private:
hb_blob_t* original_blob;

View File

@ -443,8 +443,17 @@ struct cff_subset_plan {
return;
}
bool use_glyph_to_sid_map = plan->num_output_glyphs () > plan->source->get_num_glyphs () / 8.;
hb_map_t *glyph_to_sid_map = use_glyph_to_sid_map ? acc.create_glyph_to_sid_map () : nullptr;
hb_map_t *glyph_to_sid_map = (plan->accelerator && plan->accelerator->cff_accelerator) ?
plan->accelerator->cff_accelerator->glyph_to_sid_map :
nullptr;
bool created_map = false;
if (!glyph_to_sid_map &&
((plan->accelerator && plan->accelerator->cff_accelerator) ||
plan->num_output_glyphs () > plan->source->get_num_glyphs () / 8.))
{
created_map = true;
glyph_to_sid_map = acc.create_glyph_to_sid_map ();
}
unsigned int glyph;
for (glyph = 1; glyph < plan->num_output_glyphs (); glyph++)
@ -468,8 +477,12 @@ struct cff_subset_plan {
last_sid = sid;
}
if (glyph_to_sid_map)
hb_map_destroy (glyph_to_sid_map);
if (created_map)
{
if (!(plan->accelerator && plan->accelerator->cff_accelerator) ||
!plan->accelerator->cff_accelerator->glyph_to_sid_map.cmpexch (nullptr, glyph_to_sid_map))
hb_map_destroy (glyph_to_sid_map);
}
bool two_byte = subset_charset_ranges.complete (glyph);