From 56ef4e0c52d5b474518bf0c1e4adba80f2ae6946 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 15 Oct 2017 16:38:29 -0400 Subject: [PATCH] Simplify hb_prealloced_array_t initialization --- src/hb-private.hh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 3cf8b8d3e..5deaa9d9a 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -404,7 +404,12 @@ struct hb_prealloced_array_t Type *array; Type static_array[StaticSize]; - void init (void) { memset (this, 0, sizeof (*this)); } + void init (void) + { + len = 0; + allocated = ARRAY_LENGTH (static_array); + array = static_array; + } inline Type& operator [] (unsigned int i) { return array[i]; } inline const Type& operator [] (unsigned int i) const { return array[i]; } @@ -419,11 +424,7 @@ struct hb_prealloced_array_t inline bool resize (unsigned int size) { - if (!array) { - array = static_array; - allocated = ARRAY_LENGTH (static_array); - } - if (size > allocated) + if (unlikely (size > allocated)) { /* Need to reallocate */