From 8c616a6efe7370e110d6a2f822bb1a38bf768ea6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 17:49:54 -0600 Subject: [PATCH 1/3] [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; From 6106ef8c0f61453c38c58f71a045481bf5546f2d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 18:12:09 -0600 Subject: [PATCH 2/3] [cff] Tighten up arg-stack access --- src/hb-cff-interp-common.hh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 0b5ee3cc1..bd23e74ad 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -360,7 +360,11 @@ struct cff_stack_t ELEM& operator [] (unsigned int i) { - if (unlikely (i >= count)) set_error (); + if (unlikely (i >= count)) + { + set_error (); + return Crap (ELEM); + } return elements[i]; } @@ -426,7 +430,10 @@ struct cff_stack_t unsigned int get_count () const { return count; } bool is_empty () const { return !count; } - protected: + hb_array_t get_subarray (unsigned int start) const + { return hb_array_t (elements).sub_array (start); } + + private: bool error; unsigned int count; ELEM elements[LIMIT]; @@ -484,9 +491,6 @@ struct arg_stack_t : cff_stack_t return true; } - hb_array_t get_subarray (unsigned int start) const - { return hb_array_t (S::elements).sub_array (start); } - private: typedef cff_stack_t S; }; From 1b14d2ff136a9f7522995393fda6f6644377657f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 18:15:31 -0600 Subject: [PATCH 3/3] [cff] Fix arg-stack peek() impl --- src/hb-cff-interp-common.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index bd23e74ad..2a9e60ffd 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -406,7 +406,7 @@ struct cff_stack_t const ELEM& peek () { - if (unlikely (count < 0)) + if (unlikely (count == 0)) { set_error (); return Null (ELEM);