From a180ae43ce0ae8bccc45913a6443c0d109ce7ee9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 16 Jan 2023 13:06:30 -0700 Subject: [PATCH] [bit-set] Use for loop instead of memset for page clear Produces faster code. --- src/hb-bit-page.hh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/hb-bit-page.hh b/src/hb-bit-page.hh index 7fcc296cd..37e3f7f14 100644 --- a/src/hb-bit-page.hh +++ b/src/hb-bit-page.hh @@ -42,7 +42,16 @@ struct hb_vector_size_t elt_t& operator [] (unsigned int i) { return v[i]; } const elt_t& operator [] (unsigned int i) const { return v[i]; } - void clear (unsigned char v = 0) { hb_memset (this, v, sizeof (*this)); } + void init0 () + { + for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) + v[i] = 0; + } + void init1 () + { + for (unsigned int i = 0; i < ARRAY_LENGTH (v); i++) + v[i] = (elt_t) -1; + } template hb_vector_size_t process (const Op& op) const @@ -80,8 +89,8 @@ struct hb_vector_size_t struct hb_bit_page_t { - void init0 () { v.clear (); } - void init1 () { v.clear (0xFF); } + void init0 () { v.init0 (); } + void init1 () { v.init1 (); } constexpr unsigned len () const { return ARRAY_LENGTH_CONST (v); }