diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 3fea5d995..5c6988d79 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -188,6 +188,17 @@ template <> struct hb_int_max : hb_integral_constant struct hb_int_max : hb_integral_constant {}; #define hb_int_max(T) hb_int_max::value +#if __GNUG__ && __GNUC__ < 5 +#define hb_is_trivially_copyable(T) __has_trivial_copy(T) +#define hb_is_trivially_copy_assignable(T) (__has_trivial_copy(T) && __has_trivial_assign(T)) +#define hb_is_trivially_constructible(T) __has_trivial_constructor(T) +#define hb_is_trivially_destructible(T) __has_trivial_destructor(T) +#else +#define hb_is_trivially_copyable(T) std::is_trivially_copyable::value +#define hb_is_trivially_copy_assignable(T) std::is_trivially_copy_assignable::value +#define hb_is_trivially_constructible(T) std::is_trivially_constructible::value +#define hb_is_trivially_destructible(T) std::is_trivially_destructible::value +#endif /* Class traits. */ diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 7e524177f..aee7064be 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -33,6 +33,7 @@ #include "hb-blob.hh" #include "hb-face.hh" #include "hb-machinery.hh" +#include "hb-meta.hh" #include "hb-subset.hh" @@ -518,7 +519,7 @@ struct UnsizedArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c, count))) return_trace (false); - if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); + if (!sizeof... (Ts) && hb_is_trivially_copyable(Type)) return_trace (true); for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); @@ -707,7 +708,7 @@ struct ArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); + if (!sizeof... (Ts) && hb_is_trivially_copyable(Type)) return_trace (true); unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) @@ -835,7 +836,7 @@ struct HeadlessArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); + if (!sizeof... (Ts) && hb_is_trivially_copyable(Type)) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) @@ -884,7 +885,7 @@ struct ArrayOfM1 { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); + if (!sizeof... (Ts) && hb_is_trivially_copyable(Type)) return_trace (true); unsigned int count = lenM1 + 1; for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) @@ -1070,7 +1071,7 @@ struct VarSizedBinSearchArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); + if (!sizeof... (Ts) && hb_is_trivially_copyable(Type)) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!(*this)[i].sanitize (c, std::forward (ds)...))) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index b275b522f..a02aa3c60 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -29,6 +29,7 @@ #include "hb.hh" #include "hb-array.hh" +#include "hb-meta.hh" #include "hb-null.hh" @@ -202,14 +203,14 @@ struct hb_vector_t : std::conditional, hb_empty bool in_error () const { return allocated < 0; } template ::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 ::value)> + hb_enable_if (!hb_is_trivially_copy_assignable(T))> Type * realloc_vector (unsigned new_allocated) { @@ -229,7 +230,7 @@ struct hb_vector_t : std::conditional, hb_empty } template ::value || + hb_enable_if (hb_is_trivially_constructible(T) || !std::is_default_constructible::value)> void grow_vector (unsigned size) @@ -238,7 +239,7 @@ struct hb_vector_t : std::conditional, hb_empty length = size; } template ::value && + hb_enable_if (!hb_is_trivially_constructible(T) && std::is_default_constructible::value)> void grow_vector (unsigned size) @@ -251,14 +252,14 @@ struct hb_vector_t : std::conditional, hb_empty } template ::value)> + hb_enable_if (hb_is_trivially_destructible(T))> void shrink_vector (unsigned size) { length = size; } template ::value)> + hb_enable_if (!hb_is_trivially_destructible(T))> void shrink_vector (unsigned size) { @@ -270,7 +271,7 @@ struct hb_vector_t : std::conditional, hb_empty } template ::value)> + hb_enable_if (hb_is_trivially_copy_assignable(T))> void shift_down_vector (unsigned i) { @@ -279,7 +280,7 @@ struct hb_vector_t : std::conditional, hb_empty (length - i) * sizeof (Type)); } template ::value)> + hb_enable_if (!hb_is_trivially_copy_assignable(T))> void shift_down_vector (unsigned i) {