[cff] Allocate stack inline instead of using hb_vector_t
Speeds up glyph_extents and glyph_shape benchmarks for CFF by 10 to 16 percent!
This commit is contained in:
parent
c941ece60f
commit
8c616a6efe
|
@ -355,10 +355,8 @@ struct cff_stack_t
|
||||||
{
|
{
|
||||||
error = false;
|
error = false;
|
||||||
count = 0;
|
count = 0;
|
||||||
elements.init ();
|
|
||||||
elements.resize (kSizeLimit);
|
|
||||||
}
|
}
|
||||||
void fini () { elements.fini (); }
|
void fini () {}
|
||||||
|
|
||||||
ELEM& operator [] (unsigned int i)
|
ELEM& operator [] (unsigned int i)
|
||||||
{
|
{
|
||||||
|
@ -368,14 +366,14 @@ struct cff_stack_t
|
||||||
|
|
||||||
void push (const ELEM &v)
|
void push (const ELEM &v)
|
||||||
{
|
{
|
||||||
if (likely (count < elements.length))
|
if (likely (count < LIMIT))
|
||||||
elements[count++] = v;
|
elements[count++] = v;
|
||||||
else
|
else
|
||||||
set_error ();
|
set_error ();
|
||||||
}
|
}
|
||||||
ELEM &push ()
|
ELEM &push ()
|
||||||
{
|
{
|
||||||
if (likely (count < elements.length))
|
if (likely (count < LIMIT))
|
||||||
return elements[count++];
|
return elements[count++];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -414,7 +412,7 @@ struct cff_stack_t
|
||||||
|
|
||||||
void unpop ()
|
void unpop ()
|
||||||
{
|
{
|
||||||
if (likely (count < elements.length))
|
if (likely (count < LIMIT))
|
||||||
count++;
|
count++;
|
||||||
else
|
else
|
||||||
set_error ();
|
set_error ();
|
||||||
|
@ -422,18 +420,16 @@ struct cff_stack_t
|
||||||
|
|
||||||
void clear () { count = 0; }
|
void clear () { count = 0; }
|
||||||
|
|
||||||
bool in_error () const { return (error || elements.in_error ()); }
|
bool in_error () const { return (error); }
|
||||||
void set_error () { error = true; }
|
void set_error () { error = true; }
|
||||||
|
|
||||||
unsigned int get_count () const { return count; }
|
unsigned int get_count () const { return count; }
|
||||||
bool is_empty () const { return !count; }
|
bool is_empty () const { return !count; }
|
||||||
|
|
||||||
static constexpr unsigned kSizeLimit = LIMIT;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool error;
|
bool error;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
hb_vector_t<ELEM> elements;
|
ELEM elements[LIMIT];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* argument stack */
|
/* argument stack */
|
||||||
|
@ -489,7 +485,7 @@ struct arg_stack_t : cff_stack_t<ARG, 513>
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_array_t<const ARG> get_subarray (unsigned int start) const
|
hb_array_t<const ARG> get_subarray (unsigned int start) const
|
||||||
{ return S::elements.sub_array (start); }
|
{ return hb_array_t<const ARG> (S::elements).sub_array (start); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef cff_stack_t<ARG, 513> S;
|
typedef cff_stack_t<ARG, 513> S;
|
||||||
|
|
Loading…
Reference in New Issue