From 4dcf65328f04a11594fc190fd7e976afa54455e9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 10 May 2019 22:23:24 -0700 Subject: [PATCH] [sanitize] Simplify --- src/hb-open-type.hh | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 3fc4940..13b1245 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -440,21 +440,12 @@ struct UnsizedArrayOf return_trace (out); } - bool sanitize (hb_sanitize_context_t *c, unsigned int count) const - { - TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c, count))) return_trace (false); - - static_assert ((hb_void_t (), true), ""); - static_assert (hb_is_trivially_copyable (Type), ""); - - return_trace (true); - } template bool sanitize (hb_sanitize_context_t *c, unsigned int count, Ts&&... ds) const { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c, count))) return_trace (false); + if (hb_is_trivially_copyable (Type)) return_trace (true); for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) return_trace (false); @@ -609,21 +600,12 @@ struct ArrayOf return_trace (out); } - bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return_trace (false); - - static_assert ((hb_void_t (), true), ""); - static_assert (hb_is_trivially_copyable (Type), ""); - - return_trace (true); - } template bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); + if (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], hb_forward (ds)...))) @@ -736,14 +718,16 @@ struct HeadlessArrayOf return_trace (true); } - bool sanitize (hb_sanitize_context_t *c) const + template + bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - - static_assert ((hb_void_t (), true), ""); - static_assert (hb_is_trivially_copyable (Type), ""); - + if (hb_is_trivially_copyable (Type)) return_trace (true); + unsigned int count = lenP1 ? lenP1 - 1 : 0; + for (unsigned int i = 0; i < count; i++) + if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + return_trace (false); return_trace (true); } @@ -965,21 +949,12 @@ struct VarSizedBinSearchArrayOf unsigned int get_size () const { return header.static_size + header.nUnits * header.unitSize; } - bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return_trace (false); - - static_assert ((hb_void_t (), true), ""); - static_assert (hb_is_trivially_copyable (Type), ""); - - return_trace (true); - } template bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); + if (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, hb_forward (ds)...))) -- 2.7.4