diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-12-22 00:39:38 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-12-22 00:39:38 +0000 |
commit | aefa260469999e53f3b8ea263fda94cdddef8ce3 (patch) | |
tree | e1182a668216a25f19d5f18ffcfec27cc7925b96 /Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh | |
parent | 27205aecce351fee6bb1ad9a7c43d4b542e28a1a (diff) |
harfbuzz-2.3.0
git-svn-id: svn://tug.org/texlive/trunk@49473 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh')
-rw-r--r-- | Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh | 277 |
1 files changed, 48 insertions, 229 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh index 5773596019d..48ce9897d5e 100644 --- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh +++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-dsalgs.hh @@ -46,7 +46,7 @@ template <typename T> static inline HB_CONST_FUNC unsigned int hb_popcount (T v) { -#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__) +#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) if (sizeof (T) <= sizeof (unsigned int)) return __builtin_popcount (v); @@ -89,7 +89,7 @@ hb_bit_storage (T v) { if (unlikely (!v)) return 0; -#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) +#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) if (sizeof (T) <= sizeof (unsigned int)) return sizeof (unsigned int) * 8 - __builtin_clz (v); @@ -163,7 +163,7 @@ hb_ctz (T v) { if (unlikely (!v)) return 0; -#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) +#if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) if (sizeof (T) <= sizeof (unsigned int)) return __builtin_ctz (v); @@ -234,6 +234,15 @@ hb_ctz (T v) * Tiny stuff. */ +template <typename T> +static inline T* hb_addressof (T& arg) +{ + /* https://en.cppreference.com/w/cpp/memory/addressof */ + return reinterpret_cast<T*>( + &const_cast<char&>( + reinterpret_cast<const volatile char&>(arg))); +} + /* ASCII tag/character handling */ static inline bool ISALPHA (unsigned char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } @@ -287,11 +296,25 @@ hb_ceil_to_4 (unsigned int v) return ((v - 1) | 3) + 1; } -template <typename T> class hb_assert_unsigned_t; -template <> class hb_assert_unsigned_t<unsigned char> {}; -template <> class hb_assert_unsigned_t<unsigned short> {}; -template <> class hb_assert_unsigned_t<unsigned int> {}; -template <> class hb_assert_unsigned_t<unsigned long> {}; +template <typename T> struct hb_is_signed; +template <> struct hb_is_signed<signed char> { enum { value = true }; }; +template <> struct hb_is_signed<signed short> { enum { value = true }; }; +template <> struct hb_is_signed<signed int> { enum { value = true }; }; +template <> struct hb_is_signed<signed long> { enum { value = true }; }; +template <> struct hb_is_signed<unsigned char> { enum { value = false }; }; +template <> struct hb_is_signed<unsigned short> { enum { value = false }; }; +template <> struct hb_is_signed<unsigned int> { enum { value = false }; }; +template <> struct hb_is_signed<unsigned long> { enum { value = false }; }; +/* We need to define hb_is_signed for the typedefs we use on pre-Visual + * Studio 2010 for the int8_t type, since __int8/__int64 is not considered + * the same as char/long. The previous lines will suffice for the other + * types, though. Note that somehow, unsigned __int8 is considered same + * as unsigned char. + * https://github.com/harfbuzz/harfbuzz/pull/1499 + */ +#if defined(_MSC_VER) && (_MSC_VER < 1600) +template <> struct hb_is_signed<__int8> { enum { value = true }; }; +#endif template <typename T> static inline bool hb_in_range (T u, T lo, T hi) @@ -301,7 +324,7 @@ hb_in_range (T u, T lo, T hi) * one right now. Declaring a variable won't work as HB_UNUSED * is unusable on some platforms and unused types are less likely * to generate a warning than unused variables. */ - static_assert ((sizeof (hb_assert_unsigned_t<T>) >= 0), ""); + static_assert (!hb_is_signed<T>::value, ""); /* The casts below are important as if T is smaller than int, * the subtract results will become a signed int! */ @@ -529,232 +552,28 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o } -struct hb_bytes_t -{ - inline hb_bytes_t (void) : arrayZ (nullptr), len (0) {} - inline hb_bytes_t (const char *bytes_, unsigned int len_) : arrayZ (bytes_), len (len_) {} - inline hb_bytes_t (const void *bytes_, unsigned int len_) : arrayZ ((const char *) bytes_), len (len_) {} - template <typename T> - inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len * sizeof (array.arrayZ[0])) {} - - inline operator const void * (void) const { return arrayZ; } - inline operator const char * (void) const { return arrayZ; } - - inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } - - inline int cmp (const hb_bytes_t &a) const - { - if (len != a.len) - return (int) a.len - (int) len; - return hb_memcmp (a.arrayZ, arrayZ, len); - } - static inline int cmp (const void *pa, const void *pb) - { - hb_bytes_t *a = (hb_bytes_t *) pa; - hb_bytes_t *b = (hb_bytes_t *) pb; - return b->cmp (*a); - } - - const char *arrayZ; - unsigned int len; -}; - -template <typename Type> -struct hb_sorted_array_t; - -template <typename Type> -struct hb_array_t -{ - static_assert ((bool) (unsigned) hb_static_size (Type), ""); - - inline hb_array_t (void) : arrayZ (nullptr), len (0) {} - inline hb_array_t (const hb_array_t &o) : arrayZ (o.arrayZ), len (o.len) {} - inline hb_array_t (Type *array_, unsigned int len_) : arrayZ (array_), len (len_) {} - - inline Type& operator [] (unsigned int i) const - { - if (unlikely (i >= len)) return Null(Type); - return arrayZ[i]; - } - - template <typename T> inline operator T * (void) const { return arrayZ; } - - inline Type * operator & (void) const { return arrayZ; } - - inline unsigned int get_size (void) const { return len * sizeof (Type); } - - inline hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int *seg_count /* IN/OUT */) const - { - if (!seg_count) return hb_array_t<Type> (); - - unsigned int count = len; - if (unlikely (start_offset > count)) - count = 0; - else - count -= start_offset; - count = *seg_count = MIN (count, *seg_count); - return hb_array_t<Type> (arrayZ + start_offset, count); - } - inline hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int seg_count) const - { return sub_array (start_offset, &seg_count); } - - inline hb_bytes_t as_bytes (void) const - { return hb_bytes_t (arrayZ, len * sizeof (Type)); } - - template <typename T> - inline Type *lsearch (const T &x, - Type *not_found = nullptr) - { - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (!this->arrayZ[i].cmp (x)) - return &this->arrayZ[i]; - return not_found; - } - template <typename T> - inline const Type *lsearch (const T &x, - const Type *not_found = nullptr) const - { - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - if (!this->arrayZ[i].cmp (x)) - return &this->arrayZ[i]; - return not_found; - } - - inline hb_sorted_array_t<Type> qsort (int (*cmp)(const void*, const void*)) - { - ::qsort (arrayZ, len, sizeof (Type), cmp); - return hb_sorted_array_t<Type> (*this); - } - inline hb_sorted_array_t<Type> qsort (void) - { - ::qsort (arrayZ, len, sizeof (Type), Type::cmp); - return hb_sorted_array_t<Type> (*this); - } - inline void qsort (unsigned int start, unsigned int end) - { - end = MIN (end, len); - assert (start <= end); - ::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp); - } - - inline void free (void) - { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } - - template <typename hb_sanitize_context_t> - inline bool sanitize (hb_sanitize_context_t *c) const - { return c->check_array (arrayZ, len); } - - public: - Type *arrayZ; - unsigned int len; -}; -template <typename T> -inline hb_array_t<T> hb_array (T *array, unsigned int len) -{ return hb_array_t<T> (array, len); } - -enum hb_bfind_not_found_t -{ - HB_BFIND_NOT_FOUND_DONT_STORE, - HB_BFIND_NOT_FOUND_STORE, - HB_BFIND_NOT_FOUND_STORE_CLOSEST, -}; - -template <typename Type> -struct hb_sorted_array_t : hb_array_t<Type> -{ - inline hb_sorted_array_t (void) : hb_array_t<Type> () {} - inline hb_sorted_array_t (const hb_array_t<Type> &o) : hb_array_t<Type> (o) {} - inline hb_sorted_array_t (Type *array_, unsigned int len_) : hb_array_t<Type> (array_, len_) {} - - inline hb_sorted_array_t<Type> sub_array (unsigned int start_offset, unsigned int *seg_count /* IN/OUT */) const - { return hb_sorted_array_t<Type> (((const hb_array_t<Type> *) (this))->sub_array (start_offset, seg_count)); } - inline hb_sorted_array_t<Type> sub_array (unsigned int start_offset, unsigned int seg_count) const - { return sub_array (start_offset, &seg_count); } - - template <typename T> - inline Type *bsearch (const T &x, Type *not_found = nullptr) - { - unsigned int i; - return bfind (x, &i) ? &this->arrayZ[i] : not_found; - } - template <typename T> - inline const Type *bsearch (const T &x, const Type *not_found = nullptr) const - { - unsigned int i; - return bfind (x, &i) ? &this->arrayZ[i] : not_found; - } - template <typename T> - inline bool bfind (const T &x, unsigned int *i = nullptr, - 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->len - 1; - const Type *array = this->arrayZ; - while (min <= max) - { - 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) - { - switch (not_found) - { - case HB_BFIND_NOT_FOUND_DONT_STORE: - break; - - case HB_BFIND_NOT_FOUND_STORE: - *i = to_store; - break; - - case HB_BFIND_NOT_FOUND_STORE_CLOSEST: - if (max < 0 || (max < (int) this->len && array[max].cmp (x) > 0)) - max++; - *i = max; - break; - } - } - return false; - } -}; -template <typename T> -inline hb_sorted_array_t<T> hb_sorted_array (T *array, unsigned int len) -{ return hb_sorted_array_t<T> (array, len); } - - struct HbOpOr { - static const bool passthru_left = true; - static const bool passthru_right = true; + enum { passthru_left = true }; + enum { passthru_right = true }; template <typename T> static void process (T &o, const T &a, const T &b) { o = a | b; } }; struct HbOpAnd { - static const bool passthru_left = false; - static const bool passthru_right = false; + enum { passthru_left = false }; + enum { passthru_right = false }; template <typename T> static void process (T &o, const T &a, const T &b) { o = a & b; } }; struct HbOpMinus { - static const bool passthru_left = true; - static const bool passthru_right = false; + enum { passthru_left = true }; + enum { passthru_right = false }; template <typename T> static void process (T &o, const T &a, const T &b) { o = a & ~b; } }; struct HbOpXor { - static const bool passthru_left = true; - static const bool passthru_right = true; + enum { passthru_left = true }; + enum { passthru_right = true }; template <typename T> static void process (T &o, const T &a, const T &b) { o = a ^ b; } }; @@ -767,13 +586,13 @@ struct HbOpXor template <typename elt_t, unsigned int byte_size> struct hb_vector_size_t { - inline elt_t& operator [] (unsigned int i) { return u.v[i]; } - inline const elt_t& operator [] (unsigned int i) const { return u.v[i]; } + elt_t& operator [] (unsigned int i) { return u.v[i]; } + const elt_t& operator [] (unsigned int i) const { return u.v[i]; } - inline void clear (unsigned char v = 0) { memset (this, v, sizeof (*this)); } + void clear (unsigned char v = 0) { memset (this, v, sizeof (*this)); } template <class Op> - inline hb_vector_size_t process (const hb_vector_size_t &o) const + hb_vector_size_t process (const hb_vector_size_t &o) const { hb_vector_size_t r; #if HB_VECTOR_SIZE @@ -786,13 +605,13 @@ struct hb_vector_size_t Op::process (r.u.v[i], u.v[i], o.u.v[i]); return r; } - inline hb_vector_size_t operator | (const hb_vector_size_t &o) const + hb_vector_size_t operator | (const hb_vector_size_t &o) const { return process<HbOpOr> (o); } - inline hb_vector_size_t operator & (const hb_vector_size_t &o) const + hb_vector_size_t operator & (const hb_vector_size_t &o) const { return process<HbOpAnd> (o); } - inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const + hb_vector_size_t operator ^ (const hb_vector_size_t &o) const { return process<HbOpXor> (o); } - inline hb_vector_size_t operator ~ () const + hb_vector_size_t operator ~ () const { hb_vector_size_t r; #if HB_VECTOR_SIZE && 0 |