[subset] speedup cmap4 subsetting for large codepoint counts. (#3178)
glyphIdArray generation implementation was O(n^2). Refactored to use a hashmap to reduce complexity. After the change subset time for a 22k codepoint subset went from 7s to 0.7s.
This commit is contained in:
parent
fdce294120
commit
b9a176e268
|
@ -218,29 +218,24 @@ struct CmapSubtableFormat4
|
||||||
HBINT16 *idDelta,
|
HBINT16 *idDelta,
|
||||||
unsigned segcount)
|
unsigned segcount)
|
||||||
{
|
{
|
||||||
|
hb_hashmap_t<hb_codepoint_t, hb_codepoint_t> cp_to_gid;
|
||||||
|
+ it | hb_sink (cp_to_gid);
|
||||||
|
|
||||||
HBUINT16 *idRangeOffset = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount);
|
HBUINT16 *idRangeOffset = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount);
|
||||||
if (unlikely (!c->check_success (idRangeOffset))) return nullptr;
|
if (unlikely (!c->check_success (idRangeOffset))) return nullptr;
|
||||||
if (unlikely ((char *)idRangeOffset - (char *)idDelta != (int) segcount * (int) HBINT16::static_size)) return nullptr;
|
if (unlikely ((char *)idRangeOffset - (char *)idDelta != (int) segcount * (int) HBINT16::static_size)) return nullptr;
|
||||||
|
|
||||||
+ hb_range (segcount)
|
for (unsigned i : + hb_range (segcount)
|
||||||
| hb_filter ([&] (const unsigned _) { return idDelta[_] == 0; })
|
| hb_filter ([&] (const unsigned _) { return idDelta[_] == 0; }))
|
||||||
| hb_apply ([&] (const unsigned i)
|
{
|
||||||
{
|
idRangeOffset[i] = 2 * (c->start_embed<HBUINT16> () - idRangeOffset - i);
|
||||||
idRangeOffset[i] = 2 * (c->start_embed<HBUINT16> () - idRangeOffset - i);
|
for (hb_codepoint_t cp = startCode[i]; cp <= endCode[i]; cp++)
|
||||||
|
{
|
||||||
+ it
|
HBUINT16 gid;
|
||||||
| hb_filter ([&] (const hb_item_type<Iterator> _) { return _.first >= startCode[i] && _.first <= endCode[i]; })
|
gid = cp_to_gid[cp];
|
||||||
| hb_apply ([&] (const hb_item_type<Iterator> _)
|
c->copy<HBUINT16> (gid);
|
||||||
{
|
}
|
||||||
HBUINT16 glyID;
|
}
|
||||||
glyID = _.second;
|
|
||||||
c->copy<HBUINT16> (glyID);
|
|
||||||
})
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
;
|
|
||||||
|
|
||||||
return idRangeOffset;
|
return idRangeOffset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue