From 2fb3a8327ab35248a0c7877c48422718cfbe375d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 10 May 2019 18:40:29 -0700 Subject: [PATCH] [vector] Simplify arrayZ Was turned into function when we had static ones and wanted to be move-safe... Not the case anymore. --- src/hb-coretext.cc | 2 +- src/hb-ot-cff-common.hh | 2 +- src/hb-uniscribe.cc | 10 +++---- src/hb-vector.hh | 71 ++++++++++++++++++++++--------------------------- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index bf8e96c..3834285 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -598,7 +598,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, } else { active_feature_t *feature = active_features.find (&event->feature); if (feature) - active_features.remove (feature - active_features.arrayZ ()); + active_features.remove (feature - active_features.arrayZ); } } } diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index e7ac0ba..5d80943 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -167,7 +167,7 @@ struct CFFIndex byteArray.resize (buffArray.length); for (unsigned int i = 0; i < byteArray.length; i++) { - byteArray[i] = byte_str_t (buffArray[i].arrayZ (), buffArray[i].length); + byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length); } bool result = this->serialize (c, offSize_, byteArray); byteArray.fini (); diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index ac4ff63..4e00441 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -698,7 +698,7 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, { active_feature_t *feature = active_features.find (&event->feature); if (feature) - active_features.remove (feature - active_features.arrayZ ()); + active_features.remove (feature - active_features.arrayZ); } } @@ -889,8 +889,8 @@ retry: &items[i].a, script_tags[i], language_tag, - range_char_counts.arrayZ (), - range_properties.arrayZ (), + range_char_counts.arrayZ, + range_properties.arrayZ, range_properties.length, pchars + chars_offset, item_chars_len, @@ -930,8 +930,8 @@ retry: &items[i].a, script_tags[i], language_tag, - range_char_counts.arrayZ (), - range_properties.arrayZ (), + range_char_counts.arrayZ, + range_properties.arrayZ, range_properties.length, pchars + chars_offset, log_clusters + chars_offset, diff --git a/src/hb-vector.hh b/src/hb-vector.hh index e0b7fb0..3c6347b 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -49,35 +49,34 @@ struct hb_vector_t { allocated = o.allocated; length = o.length; - arrayZ_ = o.arrayZ_; + arrayZ = o.arrayZ; o.init (); } ~hb_vector_t () { fini (); } - unsigned int length; private: int allocated; /* == -1 means allocation failed. */ - Type *arrayZ_; public: + unsigned int length; + public: + Type *arrayZ; void init () { allocated = length = 0; - arrayZ_ = nullptr; + arrayZ = nullptr; } void fini () { - if (arrayZ_) - free (arrayZ_); + free (arrayZ); init (); } void fini_deep () { - Type *array = arrayZ(); unsigned int count = length; for (unsigned int i = 0; i < count; i++) - array[i].fini (); + arrayZ[i].fini (); fini (); } @@ -95,33 +94,30 @@ struct hb_vector_t fini (); allocated = o.allocated; length = o.length; - arrayZ_ = o.arrayZ_; + arrayZ = o.arrayZ; o.init (); return *this; } hb_bytes_t as_bytes () const - { return hb_bytes_t ((const char *) arrayZ(), length * item_size); } + { return hb_bytes_t ((const char *) arrayZ, length * item_size); } bool operator == (const hb_vector_t &o) const { return as_array () == o.as_array (); } uint32_t hash () const { return as_array ().hash (); } - const Type * arrayZ () const { return arrayZ_; } - Type * arrayZ () { return arrayZ_; } - Type& operator [] (int i_) { unsigned int i = (unsigned int) i_; if (unlikely (i >= length)) return Crap (Type); - return arrayZ()[i]; + return arrayZ[i]; } const Type& operator [] (int i_) const { unsigned int i = (unsigned int) i_; if (unlikely (i >= length)) return Null(Type); - return arrayZ()[i]; + return arrayZ[i]; } Type& tail () { return (*this)[length - 1]; } @@ -134,8 +130,8 @@ struct hb_vector_t template hb_vector_t& operator << (T&& v) { push (hb_forward (v)); return *this; } - hb_array_t< Type> as_array () { return hb_array (arrayZ(), length); } - hb_array_t as_array () const { return hb_array (arrayZ(), length); } + hb_array_t< Type> as_array () { return hb_array (arrayZ, length); } + hb_array_t as_array () const { return hb_array (arrayZ, length); } /* Iterator. */ typedef hb_array_t iter_t; @@ -155,21 +151,21 @@ struct hb_vector_t { return as_array ().sub_array (start_offset, count);} hb_sorted_array_t as_sorted_array () - { return hb_sorted_array (arrayZ(), length); } + { return hb_sorted_array (arrayZ, length); } hb_sorted_array_t as_sorted_array () const - { return hb_sorted_array (arrayZ(), length); } + { return hb_sorted_array (arrayZ, length); } - template explicit operator T * () { return arrayZ(); } - template explicit operator const T * () const { return arrayZ(); } + template explicit operator T * () { return arrayZ; } + template explicit operator const T * () const { return arrayZ; } - Type * operator + (unsigned int i) { return arrayZ() + i; } - const Type * operator + (unsigned int i) const { return arrayZ() + i; } + Type * operator + (unsigned int i) { return arrayZ + i; } + const Type * operator + (unsigned int i) const { return arrayZ + i; } Type *push () { if (unlikely (!resize (length + 1))) return &Crap(Type); - return &arrayZ()[length - 1]; + return &arrayZ[length - 1]; } template Type *push (T&& v) @@ -202,7 +198,7 @@ struct hb_vector_t (new_allocated < (unsigned) allocated) || hb_unsigned_mul_overflows (new_allocated, sizeof (Type)); if (likely (!overflows)) - new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type)); + new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type)); if (unlikely (!new_array)) { @@ -210,7 +206,7 @@ struct hb_vector_t return false; } - arrayZ_ = new_array; + arrayZ = new_array; allocated = new_allocated; return true; @@ -223,7 +219,7 @@ struct hb_vector_t return false; if (size > length) - memset (arrayZ() + length, 0, (size - length) * sizeof (*arrayZ())); + memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ)); length = size; return true; @@ -232,16 +228,15 @@ struct hb_vector_t Type pop () { if (!length) return Null(Type); - return hb_move (arrayZ()[--length]); /* Does this move actually work? */ + return hb_move (arrayZ[--length]); /* Does this move actually work? */ } void remove (unsigned int i) { if (unlikely (i >= length)) return; - Type *array = arrayZ(); - memmove (static_cast (&array[i]), - static_cast (&array[i + 1]), + memmove (static_cast (&arrayZ[i]), + static_cast (&arrayZ[i + 1]), (length - i - 1) * sizeof (Type)); length--; } @@ -256,19 +251,17 @@ struct hb_vector_t template Type *find (T v) { - Type *array = arrayZ(); for (unsigned int i = 0; i < length; i++) - if (array[i] == v) - return &array[i]; + if (arrayZ[i] == v) + return &arrayZ[i]; return nullptr; } template const Type *find (T v) const { - const Type *array = arrayZ(); for (unsigned int i = 0; i < length; i++) - if (array[i] == v) - return &array[i]; + if (arrayZ[i] == v) + return &arrayZ[i]; return nullptr; } @@ -288,8 +281,8 @@ struct hb_vector_t template struct hb_sorted_vector_t : hb_vector_t { - hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ(), this->length); } - hb_sorted_array_t as_array () const { return hb_sorted_array (this->arrayZ(), this->length); } + hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } + hb_sorted_array_t as_array () const { return hb_sorted_array (this->arrayZ, this->length); } /* Iterator. */ typedef hb_sorted_array_t const_iter_t; -- 2.7.4