[layout] Use dispatch() for add_coverage()
authorBehdad Esfahbod <behdad@behdad.org>
Tue, 17 Feb 2015 16:15:34 +0000 (19:15 +0300)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 25 Feb 2015 23:43:29 +0000 (15:43 -0800)
src/hb-ot-layout-gpos-table.hh
src/hb-ot-layout-gsub-table.hh
src/hb-ot-layout-gsubgpos-private.hh

index b804bdd..8ae4c83 100644 (file)
@@ -1506,16 +1506,8 @@ struct PosLookup : Lookup
   template <typename set_t>
   inline void add_coverage (set_t *glyphs) const
   {
-    hb_get_coverage_context_t c;
-    const Coverage *last = NULL;
-    unsigned int count = get_subtable_count ();
-    for (unsigned int i = 0; i < count; i++) {
-      const Coverage *coverage = &get_subtable (i).dispatch (&c, get_type ());
-      if (coverage != last) {
-        coverage->add_coverage (glyphs);
-        last = coverage;
-      }
-    }
+    hb_add_coverage_context_t<set_t> c (glyphs);
+    dispatch (&c);
   }
 
   inline bool apply_once (hb_apply_context_t *c) const
index c1d64b5..ed8604f 100644 (file)
@@ -1200,16 +1200,8 @@ struct SubstLookup : Lookup
   template <typename set_t>
   inline void add_coverage (set_t *glyphs) const
   {
-    hb_get_coverage_context_t c;
-    const Coverage *last = NULL;
-    unsigned int count = get_subtable_count ();
-    for (unsigned int i = 0; i < count; i++) {
-      const Coverage *coverage = &get_subtable (i).dispatch (&c, get_type ());
-      if (coverage != last) {
-        coverage->add_coverage (glyphs);
-        last = coverage;
-      }
-    }
+    hb_add_coverage_context_t<set_t> c (glyphs);
+    dispatch (&c);
   }
 
   inline bool would_apply (hb_would_apply_context_t *c,
index 2751c82..b060a69 100644 (file)
@@ -238,7 +238,8 @@ struct hb_collect_glyphs_context_t
 #define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0)
 #endif
 
-struct hb_get_coverage_context_t
+template <typename set_t>
+struct hb_add_coverage_context_t
 {
   inline const char *get_name (void) { return "GET_COVERAGE"; }
   static const unsigned int max_debug_depth = HB_DEBUG_GET_COVERAGE;
@@ -248,10 +249,17 @@ struct hb_get_coverage_context_t
   template <typename T>
   inline return_t dispatch (const T &obj) { return obj.get_coverage (); }
   static return_t default_return_value (void) { return Null(Coverage); }
+  bool stop_sublookup_iteration (return_t r) const
+  {
+    r.add_coverage (set);
+    return false;
+  }
 
-  hb_get_coverage_context_t (void) :
+  hb_add_coverage_context_t (set_t *set_) :
+                           set (set_),
                            debug_depth (0) {}
 
+  set_t *set;
   unsigned int debug_depth;
 };