From ac350c92fd6b04845c6240a5f3b77ceaf29e51d0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 5 May 2019 09:10:46 -0700 Subject: [PATCH] [dispatch] Try obj.dispatch(c) before trying c->dispatch(obj) --- src/hb-aat-layout-common.hh | 2 +- src/hb-dispatch.hh | 13 +++++++++++++ src/hb-ot-layout-gsubgpos.hh | 14 +++++++------- src/hb-sanitize.hh | 2 +- src/hb-subset.hh | 4 ++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 95ac2712..a17da372 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -807,7 +807,7 @@ struct hb_aat_apply_context_t : { const char *get_name () { return "APPLY"; } template - return_t dispatch (const T &obj) { return obj.apply (this); } + return_t _dispatch (const T &obj) { return obj.apply (this); } static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index c4347a6c..e5820744 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -38,12 +38,25 @@ template struct hb_dispatch_context_t { + private: + /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ + const Context* thiz () const { return static_cast (this); } + Context* thiz () { return static_cast< Context *> (this); } + public: static constexpr unsigned max_debug_depth = MaxDebugDepth; typedef Return return_t; template bool may_dispatch (const T *obj HB_UNUSED, const F *format HB_UNUSED) { return true; } + template + return_t dispatch (const T &obj) { return _dispatch_impl (obj, hb_prioritize); } static return_t no_dispatch_return_value () { return Context::default_return_value (); } static bool stop_sublookup_iteration (const return_t r HB_UNUSED) { return false; } + + private: + template + auto _dispatch_impl (const T &obj, hb_priority<1>) HB_AUTO_RETURN (obj.dispatch (thiz ())) + template + Return _dispatch_impl (const T &obj, hb_priority<0>) { return thiz()->_dispatch (obj); } }; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 6b0b7ad5..9960b403 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -46,7 +46,7 @@ struct hb_intersects_context_t : { const char *get_name () { return "INTERSECTS"; } template - return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } + return_t _dispatch (const T &obj) { return obj.intersects (this->glyphs); } static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } @@ -64,7 +64,7 @@ struct hb_closure_context_t : const char *get_name () { return "CLOSURE"; } typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); template - return_t dispatch (const T &obj) { obj.closure (this); return hb_void_t (); } + return_t _dispatch (const T &obj) { obj.closure (this); return hb_void_t (); } static return_t default_return_value () { return hb_void_t (); } void recurse (unsigned int lookup_index) { @@ -128,7 +128,7 @@ struct hb_would_apply_context_t : { const char *get_name () { return "WOULD_APPLY"; } template - return_t dispatch (const T &obj) { return obj.would_apply (this); } + return_t _dispatch (const T &obj) { return obj.would_apply (this); } static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } @@ -156,7 +156,7 @@ struct hb_collect_glyphs_context_t : const char *get_name () { return "COLLECT_GLYPHS"; } typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); template - return_t dispatch (const T &obj) { obj.collect_glyphs (this); return hb_void_t (); } + return_t _dispatch (const T &obj) { obj.collect_glyphs (this); return hb_void_t (); } static return_t default_return_value () { return hb_void_t (); } void recurse (unsigned int lookup_index) { @@ -235,7 +235,7 @@ struct hb_add_coverage_context_t : const char *get_name () { return "GET_COVERAGE"; } typedef const Coverage &return_t; template - return_t dispatch (const T &obj) { return obj.get_coverage (); } + return_t _dispatch (const T &obj) { return obj.get_coverage (); } static return_t default_return_value () { return Null(Coverage); } bool stop_sublookup_iteration (return_t r) const { @@ -438,7 +438,7 @@ struct hb_ot_apply_context_t : const char *get_name () { return "APPLY"; } typedef return_t (*recurse_func_t) (hb_ot_apply_context_t *c, unsigned int lookup_index); template - return_t dispatch (const T &obj) { return obj.apply (this); } + return_t _dispatch (const T &obj) { return obj.apply (this); } static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } return_t recurse (unsigned int sub_lookup_index) @@ -648,7 +648,7 @@ struct hb_get_subtables_context_t : /* Dispatch interface. */ const char *get_name () { return "GET_SUBTABLES"; } template - return_t dispatch (const T &obj) + return_t _dispatch (const T &obj) { hb_applicable_t *entry = array.push(); entry->init (obj, apply_to); diff --git a/src/hb-sanitize.hh b/src/hb-sanitize.hh index e58202cf..9cf17e5f 100644 --- a/src/hb-sanitize.hh +++ b/src/hb-sanitize.hh @@ -131,7 +131,7 @@ struct hb_sanitize_context_t : bool may_dispatch (const T *obj HB_UNUSED, const F *format) { return format->sanitize (this); } template - return_t dispatch (const T &obj) { return obj.sanitize (this); } + return_t _dispatch (const T &obj) { return obj.sanitize (this); } static return_t default_return_value () { return true; } static return_t no_dispatch_return_value () { return false; } bool stop_sublookup_iteration (const return_t r) const { return !r; } diff --git a/src/hb-subset.hh b/src/hb-subset.hh index 45cb763e..795859dd 100644 --- a/src/hb-subset.hh +++ b/src/hb-subset.hh @@ -41,8 +41,8 @@ struct hb_subset_context_t : { const char *get_name () { return "SUBSET"; } template - bool dispatch (const T &obj) { return obj.subset (this); } - static bool default_return_value () { return true; } + return_t _dispatch (const T &obj) { return obj.subset (this); } + static return_t default_return_value () { return true; } hb_subset_plan_t *plan; hb_serialize_context_t *serializer; -- GitLab