[layout] Refactor Lookup::dispatch()
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 18 Feb 2015 10:18:46 +0000 (13:18 +0300)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 25 Feb 2015 23:43:30 +0000 (15:43 -0800)
src/hb-ot-layout-common-private.hh
src/hb-ot-layout-gpos-table.hh
src/hb-ot-layout-gsub-table.hh
src/hb-ot-layout-gsubgpos-private.hh

index 9dfac67..e1437fc 100644 (file)
 namespace OT {
 
 
+#define TRACE_DISPATCH(this, format) \
+       hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \
+       (&c->debug_depth, c->get_name (), this, HB_FUNC, \
+        "format %d", (int) format);
+
+
 #define NOT_COVERED            ((unsigned int) -1)
 #define MAX_NESTING_LEVEL      8
 #define MAX_CONTEXT_LENGTH     64
@@ -598,6 +604,20 @@ struct Lookup
     return flag;
   }
 
+  template <typename SubTableType, typename context_t>
+  inline typename context_t::return_t dispatch (context_t *c) const
+  {
+    unsigned int lookup_type = get_type ();
+    TRACE_DISPATCH (this, lookup_type);
+    unsigned int count = get_subtable_count ();
+    for (unsigned int i = 0; i < count; i++) {
+      typename context_t::return_t r = get_subtable<SubTableType> (i).dispatch (c, lookup_type);
+      if (c->stop_sublookup_iteration (r))
+        return TRACE_RETURN (r);
+    }
+    return TRACE_RETURN (c->default_return_value ());
+  }
+
   inline bool serialize (hb_serialize_context_t *c,
                         unsigned int lookup_type,
                         uint32_t lookup_props,
index 63302e2..a3599a9 100644 (file)
@@ -1524,17 +1524,7 @@ struct PosLookup : Lookup
 
   template <typename context_t>
   inline typename context_t::return_t dispatch (context_t *c) const
-  {
-    unsigned int lookup_type = get_type ();
-    TRACE_DISPATCH (this, lookup_type);
-    unsigned int count = get_subtable_count ();
-    for (unsigned int i = 0; i < count; i++) {
-      typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type);
-      if (c->stop_sublookup_iteration (r))
-        return TRACE_RETURN (r);
-    }
-    return TRACE_RETURN (c->default_return_value ());
-  }
+  { return Lookup::dispatch<PosLookupSubTable> (c); }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
index ca79f81..66ee088 100644 (file)
@@ -1284,17 +1284,7 @@ struct SubstLookup : Lookup
 
   template <typename context_t>
   inline typename context_t::return_t dispatch (context_t *c) const
-  {
-    unsigned int lookup_type = get_type ();
-    TRACE_DISPATCH (this, lookup_type);
-    unsigned int count = get_subtable_count ();
-    for (unsigned int i = 0; i < count; i++) {
-      typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type);
-      if (c->stop_sublookup_iteration (r))
-        return TRACE_RETURN (r);
-    }
-    return TRACE_RETURN (c->default_return_value ());
-  }
+  { return Lookup::dispatch<SubstLookupSubTable> (c); }
 
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
index b060a69..d891b6e 100644 (file)
 namespace OT {
 
 
-
-#define TRACE_DISPATCH(this, format) \
-       hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \
-       (&c->debug_depth, c->get_name (), this, HB_FUNC, \
-        "format %d", (int) format);
-
 #ifndef HB_DEBUG_CLOSURE
 #define HB_DEBUG_CLOSURE (HB_DEBUG+0)
 #endif