[sanitize] Simplify
authorBehdad Esfahbod <behdad@behdad.org>
Sat, 11 May 2019 05:23:24 +0000 (22:23 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 11 May 2019 05:23:24 +0000 (22:23 -0700)
src/hb-open-type.hh

index 3fc4940..13b1245 100644 (file)
@@ -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<decltype (hb_declval (Type).sanitize (c))> (), true), "");
-    static_assert (hb_is_trivially_copyable (Type), "");
-
-    return_trace (true);
-  }
   template <typename ...Ts>
   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<Ts> (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<decltype (hb_declval (Type).sanitize (c))> (), true), "");
-    static_assert (hb_is_trivially_copyable (Type), "");
-
-    return_trace (true);
-  }
   template <typename ...Ts>
   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<Ts> (ds)...)))
@@ -736,14 +718,16 @@ struct HeadlessArrayOf
     return_trace (true);
   }
 
-  bool sanitize (hb_sanitize_context_t *c) const
+  template <typename ...Ts>
+  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<decltype (hb_declval (Type).sanitize (c))> (), 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<Ts> (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<decltype (hb_declval (Type).sanitize (c))> (), true), "");
-    static_assert (hb_is_trivially_copyable (Type), "");
-
-    return_trace (true);
-  }
   template <typename ...Ts>
   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<Ts> (ds)...)))