mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-13 08:42:59 +00:00
[coord-setter] Reduce malloc pressure
~15% speedup benchmark-font draw of varc-hanzi.ttf
This commit is contained in:
parent
76c3beaf36
commit
0a1b26b862
1 changed files with 31 additions and 7 deletions
|
@ -11,22 +11,46 @@ namespace OT {
|
|||
|
||||
struct coord_setter_t
|
||||
{
|
||||
coord_setter_t (hb_array_t<const int> coords) :
|
||||
coords (coords) {}
|
||||
coord_setter_t (hb_array_t<const int> coords_)
|
||||
{
|
||||
length = coords_.length;
|
||||
if (length <= ARRAY_LENGTH (static_coords))
|
||||
hb_memcpy (static_coords, coords_.arrayZ, length * sizeof (int));
|
||||
else
|
||||
dynamic_coords.extend (coords_);
|
||||
}
|
||||
|
||||
int& operator [] (unsigned idx)
|
||||
{
|
||||
if (unlikely (idx >= HB_VAR_COMPOSITE_MAX_AXES))
|
||||
return Crap(int);
|
||||
if (coords.length < idx + 1)
|
||||
coords.resize (idx + 1);
|
||||
return coords[idx];
|
||||
|
||||
if (length <= ARRAY_LENGTH (static_coords))
|
||||
{
|
||||
if (idx < ARRAY_LENGTH (static_coords))
|
||||
{
|
||||
while (length <= idx)
|
||||
static_coords[length++] = 0;
|
||||
return static_coords[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
dynamic_coords.extend (hb_array (static_coords, length));
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamic_coords.length <= idx &&
|
||||
unlikely (!dynamic_coords.resize (idx + 1)))
|
||||
return Crap(int);
|
||||
return dynamic_coords.arrayZ[idx];
|
||||
}
|
||||
|
||||
hb_array_t<int> get_coords ()
|
||||
{ return coords.as_array (); }
|
||||
{ return dynamic_coords ? dynamic_coords.as_array () : hb_array (static_coords, length); }
|
||||
|
||||
hb_vector_t<int> coords;
|
||||
unsigned length;
|
||||
int static_coords[32];
|
||||
hb_vector_t<int> dynamic_coords;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue