diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2022-05-21 02:44:01 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2022-05-21 02:44:01 +0000 |
commit | 523ea68050bb0a979133708d95cb9ebf43302839 (patch) | |
tree | 381c8ccc5f5c102ea6e3dd72f0d30bc19cc1fa51 /Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh | |
parent | a6ef6aa084c7849d385575f057cfc19bc732c625 (diff) |
harfbuzz 4.3.0
git-svn-id: svn://tug.org/texlive/trunk@63353 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh')
-rw-r--r-- | Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh | 97 |
1 files changed, 78 insertions, 19 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh index 6c7d32e49d8..7b08e3b4d27 100644 --- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh +++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-vector.hh @@ -29,6 +29,7 @@ #include "hb.hh" #include "hb-array.hh" +#include "hb-meta.hh" #include "hb-null.hh" @@ -42,6 +43,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty using c_array_t = typename std::conditional<sorted, hb_sorted_array_t<const Type>, hb_array_t<const Type>>::type; hb_vector_t () = default; + hb_vector_t (std::nullptr_t) : hb_vector_t () {} hb_vector_t (std::initializer_list<Type> lst) : hb_vector_t () { alloc (lst.size ()); @@ -59,7 +61,8 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty hb_vector_t (const hb_vector_t &o) : hb_vector_t () { alloc (o.length); - hb_copy (o, *this); + if (unlikely (in_error ())) return; + copy_vector (o); } hb_vector_t (hb_vector_t &&o) { @@ -70,9 +73,8 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty } ~hb_vector_t () { fini (); } - private: - int allocated = 0; /* == -1 means allocation failed. */ public: + int allocated = 0; /* == -1 means allocation failed. */ unsigned int length = 0; public: Type *arrayZ = nullptr; @@ -108,7 +110,10 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty { reset (); alloc (o.length); - hb_copy (o, *this); + if (unlikely (in_error ())) return *this; + + copy_vector (o); + return *this; } hb_vector_t& operator = (hb_vector_t &&o) @@ -184,12 +189,14 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty { if (unlikely (!resize (length + 1))) return &Crap (Type); - return &arrayZ[length - 1]; + return std::addressof (arrayZ[length - 1]); } - template <typename T> + template <typename T, + typename T2 = Type, + hb_enable_if (!std::is_copy_constructible<T2>::value && + std::is_copy_assignable<T>::value)> Type *push (T&& v) { - /* TODO Emplace? */ Type *p = push (); if (p == &Crap (Type)) // If push failed to allocate then don't copy v, since this may cause @@ -199,18 +206,34 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty *p = std::forward<T> (v); return p; } + template <typename T, + typename T2 = Type, + hb_enable_if (std::is_copy_constructible<T2>::value)> + Type *push (T&& v) + { + if (unlikely (!alloc (length + 1))) + // If push failed to allocate then don't copy v, since this may cause + // the created copy to leak memory since we won't have stored a + // reference to it. + return &Crap (Type); + + /* Emplace. */ + length++; + Type *p = std::addressof (arrayZ[length - 1]); + return new (p) Type (std::forward<T> (v)); + } bool in_error () const { return allocated < 0; } template <typename T = Type, - hb_enable_if (std::is_trivially_copy_assignable<T>::value)> + hb_enable_if (hb_is_trivially_copy_assignable(T))> Type * realloc_vector (unsigned new_allocated) { return (Type *) hb_realloc (arrayZ, new_allocated * sizeof (Type)); } template <typename T = Type, - hb_enable_if (!std::is_trivially_copy_assignable<T>::value)> + hb_enable_if (!hb_is_trivially_copy_assignable(T))> Type * realloc_vector (unsigned new_allocated) { @@ -230,8 +253,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty } template <typename T = Type, - hb_enable_if (std::is_trivially_constructible<T>::value || - !std::is_default_constructible<T>::value)> + hb_enable_if (hb_is_trivially_constructible(T))> void grow_vector (unsigned size) { @@ -239,8 +261,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty length = size; } template <typename T = Type, - hb_enable_if (!std::is_trivially_constructible<T>::value && - std::is_default_constructible<T>::value)> + hb_enable_if (!hb_is_trivially_constructible(T))> void grow_vector (unsigned size) { @@ -252,14 +273,52 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty } template <typename T = Type, - hb_enable_if (std::is_trivially_destructible<T>::value)> + hb_enable_if (hb_is_trivially_copyable (T))> + void + copy_vector (const hb_vector_t &other) + { + length = other.length; + hb_memcpy ((void *) arrayZ, (const void *) other.arrayZ, length * item_size); + } + template <typename T = Type, + hb_enable_if (!hb_is_trivially_copyable (T) && + std::is_copy_constructible<T>::value)> + void + copy_vector (const hb_vector_t &other) + { + length = 0; + while (length < other.length) + { + length++; + new (std::addressof (arrayZ[length - 1])) Type (other.arrayZ[length - 1]); + } + } + template <typename T = Type, + hb_enable_if (!hb_is_trivially_copyable (T) && + !std::is_copy_constructible<T>::value && + std::is_default_constructible<T>::value && + std::is_copy_assignable<T>::value)> + void + copy_vector (const hb_vector_t &other) + { + length = 0; + while (length < other.length) + { + length++; + new (std::addressof (arrayZ[length - 1])) Type (); + arrayZ[length - 1] = other.arrayZ[length - 1]; + } + } + + template <typename T = Type, + hb_enable_if (hb_is_trivially_destructible(T))> void shrink_vector (unsigned size) { length = size; } template <typename T = Type, - hb_enable_if (!std::is_trivially_destructible<T>::value)> + hb_enable_if (!hb_is_trivially_destructible(T))> void shrink_vector (unsigned size) { @@ -271,7 +330,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty } template <typename T = Type, - hb_enable_if (std::is_trivially_copy_assignable<T>::value)> + hb_enable_if (hb_is_trivially_copy_assignable(T))> void shift_down_vector (unsigned i) { @@ -280,7 +339,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty (length - i) * sizeof (Type)); } template <typename T = Type, - hb_enable_if (!std::is_trivially_copy_assignable<T>::value)> + hb_enable_if (!hb_is_trivially_copy_assignable(T))> void shift_down_vector (unsigned i) { @@ -341,7 +400,7 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty Type pop () { if (!length) return Null (Type); - Type v = std::move (arrayZ[length - 1]); + Type v = arrayZ[length - 1]; arrayZ[length - 1].~Type (); length--; return v; @@ -351,8 +410,8 @@ struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty { if (unlikely (i >= length)) return; - arrayZ[i].~Type (); shift_down_vector (i + 1); + arrayZ[length - 1].~Type (); length--; } |