mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-14 17:13:40 +00:00
[subset/cff1] Use a vector, instead of map, for glyph_to_sid_map
Much faster.
This commit is contained in:
parent
1636e112c4
commit
ffc6899b0c
4 changed files with 30 additions and 17 deletions
|
@ -329,10 +329,11 @@ struct Charset0
|
|||
return sids[glyph - 1];
|
||||
}
|
||||
|
||||
void collect_glyph_to_sid_map (hb_map_t *mapping, unsigned int num_glyphs) const
|
||||
void collect_glyph_to_sid_map (hb_vector_t<uint16_t> *mapping, unsigned int num_glyphs) const
|
||||
{
|
||||
mapping->resize (num_glyphs, false);
|
||||
for (hb_codepoint_t gid = 1; gid < num_glyphs; gid++)
|
||||
mapping->set (gid, sids[gid - 1]);
|
||||
mapping->arrayZ[gid] = sids[gid - 1];
|
||||
}
|
||||
|
||||
hb_codepoint_t get_glyph (hb_codepoint_t sid, unsigned int num_glyphs) const
|
||||
|
@ -405,8 +406,9 @@ struct Charset1_2 {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void collect_glyph_to_sid_map (hb_map_t *mapping, unsigned int num_glyphs) const
|
||||
void collect_glyph_to_sid_map (hb_vector_t<uint16_t> *mapping, unsigned int num_glyphs) const
|
||||
{
|
||||
mapping->resize (num_glyphs, false);
|
||||
hb_codepoint_t gid = 1;
|
||||
if (gid >= num_glyphs)
|
||||
return;
|
||||
|
@ -415,7 +417,7 @@ struct Charset1_2 {
|
|||
hb_codepoint_t sid = ranges[i].first;
|
||||
unsigned count = ranges[i].nLeft + 1;
|
||||
for (unsigned j = 0; j < count; j++)
|
||||
mapping->set (gid++, sid++);
|
||||
mapping->arrayZ[gid++] = sid++;
|
||||
|
||||
if (gid >= num_glyphs)
|
||||
break;
|
||||
|
@ -562,7 +564,7 @@ struct Charset
|
|||
}
|
||||
}
|
||||
|
||||
void collect_glyph_to_sid_map (hb_map_t *mapping, unsigned int num_glyphs) const
|
||||
void collect_glyph_to_sid_map (hb_vector_t<uint16_t> *mapping, unsigned int num_glyphs) const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
|
@ -1233,12 +1235,14 @@ struct cff1
|
|||
}
|
||||
}
|
||||
|
||||
hb_map_t *create_glyph_to_sid_map () const
|
||||
hb_vector_t<uint16_t> *create_glyph_to_sid_map () const
|
||||
{
|
||||
if (charset != &Null (Charset))
|
||||
{
|
||||
hb_map_t *mapping = hb_map_create ();
|
||||
mapping->set (0, 0);
|
||||
auto *mapping = (hb_vector_t<uint16_t> *) hb_malloc (sizeof (hb_vector_t<uint16_t>));
|
||||
if (unlikely (!mapping)) return nullptr;
|
||||
mapping = new (mapping) hb_vector_t<uint16_t> ();
|
||||
mapping->push (0);
|
||||
charset->collect_glyph_to_sid_map (mapping, num_glyphs);
|
||||
return mapping;
|
||||
}
|
||||
|
|
|
@ -481,7 +481,7 @@ struct cff2
|
|||
blob = nullptr;
|
||||
}
|
||||
|
||||
hb_map_t *create_glyph_to_sid_map () const
|
||||
hb_vector_t<uint16_t> *create_glyph_to_sid_map () const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -510,15 +510,21 @@ struct cff_subset_accelerator_t
|
|||
original_blob = hb_blob_reference (original_blob_);
|
||||
}
|
||||
|
||||
~cff_subset_accelerator_t() {
|
||||
~cff_subset_accelerator_t()
|
||||
{
|
||||
hb_blob_destroy (original_blob);
|
||||
hb_map_destroy (glyph_to_sid_map.get_relaxed ());
|
||||
auto *mapping = glyph_to_sid_map.get_relaxed ();
|
||||
if (mapping)
|
||||
{
|
||||
mapping->~hb_vector_t ();
|
||||
hb_free (mapping);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
mutable hb_atomic_ptr_t<hb_vector_t<uint16_t>> glyph_to_sid_map = nullptr;
|
||||
|
||||
private:
|
||||
hb_blob_t* original_blob;
|
||||
|
|
|
@ -481,9 +481,9 @@ struct cff_subset_plan {
|
|||
return;
|
||||
}
|
||||
|
||||
hb_map_t *glyph_to_sid_map = (plan->accelerator && plan->accelerator->cff_accelerator) ?
|
||||
plan->accelerator->cff_accelerator->glyph_to_sid_map :
|
||||
nullptr;
|
||||
hb_vector_t<uint16_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) ||
|
||||
|
@ -512,7 +512,7 @@ struct cff_subset_plan {
|
|||
/* Retain the SID for the old missing glyph ID */
|
||||
old_glyph = glyph;
|
||||
}
|
||||
sid = glyph_to_sid_map ? glyph_to_sid_map->get (old_glyph) : acc.glyph_to_sid (old_glyph);
|
||||
sid = glyph_to_sid_map ? glyph_to_sid_map->arrayZ[old_glyph] : acc.glyph_to_sid (old_glyph);
|
||||
|
||||
if (not_is_cid)
|
||||
sid = sidmap.add (sid);
|
||||
|
@ -529,7 +529,10 @@ struct cff_subset_plan {
|
|||
{
|
||||
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);
|
||||
{
|
||||
glyph_to_sid_map->~hb_vector_t ();
|
||||
hb_free (glyph_to_sid_map);
|
||||
}
|
||||
}
|
||||
|
||||
bool two_byte = subset_charset_ranges.complete (glyph);
|
||||
|
|
Loading…
Add table
Reference in a new issue