diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-03-23 07:45:57 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-04-06 12:55:18 +0100 |
commit | 70af64433f491ee28e8b4ff19ebf413d45960155 (patch) | |
tree | 46dd5971011d619377ed233469f33c33f303d79e /src/3rdparty/harfbuzz-ng/src/hb-array.hh | |
parent | 29450dfa283bc08f1999ac6dfc5c4956cc9af044 (diff) |
Update to Harfbuzz 2.8.0
This updates Harfbuzz to the latest version and also
adds an import script to help with this work in the
future.
Task-number: QTBUG-90217
Pick-to: 6.1
Change-Id: I23eae7b7bbbd5001df9873e4784a0c4213de5508
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-array.hh')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-array.hh | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-array.hh b/src/3rdparty/harfbuzz-ng/src/hb-array.hh index d9adf2c728..02bd8d81c2 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-array.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-array.hh @@ -129,20 +129,27 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&> template <typename T> Type *lsearch (const T &x, Type *not_found = nullptr) { - unsigned int count = length; - for (unsigned int i = 0; i < count; i++) - if (!this->arrayZ[i].cmp (x)) - return &this->arrayZ[i]; - return not_found; + unsigned i; + return lfind (x, &i) ? &this->arrayZ[i] : not_found; } template <typename T> const Type *lsearch (const T &x, const Type *not_found = nullptr) const { - unsigned int count = length; - for (unsigned int i = 0; i < count; i++) - if (!this->arrayZ[i].cmp (x)) - return &this->arrayZ[i]; - return not_found; + unsigned i; + return lfind (x, &i) ? &this->arrayZ[i] : not_found; + } + template <typename T> + bool lfind (const T &x, unsigned *pos = nullptr) const + { + for (unsigned i = 0; i < length; ++i) + if (hb_equal (x, this->arrayZ[i])) + { + if (pos) + *pos = i; + return true; + } + + return false; } hb_sorted_array_t<Type> qsort (int (*cmp_)(const void*, const void*)) @@ -171,6 +178,24 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&> unsigned int get_size () const { return length * this->get_item_size (); } + /* + * Reverse the order of items in this array in the range [start, end). + */ + void reverse (unsigned start = 0, unsigned end = -1) + { + start = hb_min (start, length); + end = hb_min (end, length); + + if (end < start + 2) + return; + + for (unsigned lhs = start, rhs = end - 1; lhs < rhs; lhs++, rhs--) { + Type temp = arrayZ[rhs]; + arrayZ[rhs] = arrayZ[lhs]; + arrayZ[lhs] = temp; + } + } + hb_array_t sub_array (unsigned int start_offset = 0, unsigned int *seg_count = nullptr /* IN/OUT */) const { if (!start_offset && !seg_count) @@ -199,10 +224,11 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&> template <typename T, unsigned P = sizeof (Type), hb_enable_if (P == 1)> - bool in_range (const T *p, unsigned int size = T::static_size) const + bool check_range (const T *p, unsigned int size = T::static_size) const { - return ((const char *) p) >= arrayZ - && ((const char *) p + size) <= arrayZ + length; + return arrayZ <= ((const char *) p) + && ((const char *) p) <= arrayZ + length + && (unsigned int) (arrayZ + length - (const char *) p) >= size; } /* Only call if you allocated the underlying array using malloc() or similar. */ @@ -300,23 +326,15 @@ struct hb_sorted_array_t : hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE, unsigned int to_store = (unsigned int) -1) const { - int min = 0, max = (int) this->length - 1; - const Type *array = this->arrayZ; - while (min <= max) + unsigned pos; + + if (bsearch_impl (x, &pos)) { - int mid = ((unsigned int) min + (unsigned int) max) / 2; - int c = array[mid].cmp (x); - if (c < 0) - max = mid - 1; - else if (c > 0) - min = mid + 1; - else - { - if (i) - *i = mid; - return true; - } + if (i) + *i = pos; + return true; } + if (i) { switch (not_found) @@ -329,14 +347,22 @@ struct hb_sorted_array_t : break; case HB_BFIND_NOT_FOUND_STORE_CLOSEST: - if (max < 0 || (max < (int) this->length && array[max].cmp (x) > 0)) - max++; - *i = max; + *i = pos; break; } } return false; } + template <typename T> + bool bsearch_impl (const T &x, unsigned *pos) const + { + return hb_bsearch_impl (pos, + x, + this->arrayZ, + this->length, + sizeof (Type), + _hb_cmp_method<T, Type>); + } }; template <typename T> inline hb_sorted_array_t<T> hb_sorted_array (T *array, unsigned int length) |