From 8c616a6efe7370e110d6a2f822bb1a38bf768ea6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 17:49:54 -0600 Subject: [PATCH] [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! --- src/hb-cff-interp-common.hh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index ab622a7a2..0b5ee3cc1 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -355,10 +355,8 @@ struct cff_stack_t { error = false; count = 0; - elements.init (); - elements.resize (kSizeLimit); } - void fini () { elements.fini (); } + void fini () {} ELEM& operator [] (unsigned int i) { @@ -368,14 +366,14 @@ struct cff_stack_t void push (const ELEM &v) { - if (likely (count < elements.length)) + if (likely (count < LIMIT)) elements[count++] = v; else set_error (); } ELEM &push () { - if (likely (count < elements.length)) + if (likely (count < LIMIT)) return elements[count++]; else { @@ -414,7 +412,7 @@ struct cff_stack_t void unpop () { - if (likely (count < elements.length)) + if (likely (count < LIMIT)) count++; else set_error (); @@ -422,18 +420,16 @@ struct cff_stack_t void clear () { count = 0; } - bool in_error () const { return (error || elements.in_error ()); } + bool in_error () const { return (error); } void set_error () { error = true; } unsigned int get_count () const { return count; } bool is_empty () const { return !count; } - static constexpr unsigned kSizeLimit = LIMIT; - protected: bool error; unsigned int count; - hb_vector_t elements; + ELEM elements[LIMIT]; }; /* argument stack */ @@ -489,7 +485,7 @@ struct arg_stack_t : cff_stack_t } hb_array_t get_subarray (unsigned int start) const - { return S::elements.sub_array (start); } + { return hb_array_t (S::elements).sub_array (start); } private: typedef cff_stack_t S;