From 6901090945d7e16102f3a2b168465434032b9a09 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 12 Aug 2018 16:57:06 -0700 Subject: [PATCH] [lazy] Make hb_lazy_loader_t<> more usable --- src/hb-ft.cc | 7 ++--- src/hb-machinery-private.hh | 57 ++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index eea2da13..e716ec91 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -685,9 +685,8 @@ hb_ft_font_create_referenced (FT_Face ft_face) static void free_static_ft_library (void); -static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t::value> +static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t::value, + hb_ft_library_lazy_loader_t> { static inline FT_Library create (void) { @@ -705,7 +704,7 @@ static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t struct hb_data_wrapper_t { - template + template inline Stored * call_create (void) const { - return Subclass::create (); + return Funcs::create (); } }; -template struct hb_non_void_t { typedef T1 value; }; +template struct hb_non_void_t { typedef T2 value; }; + +template struct hb_lazy_loader_t : hb_data_wrapper_t { + typedef typename hb_non_void_t + >::value Funcs; + inline void init0 (void) {} /* Init, when memory is already set to 0. No-op for us. */ inline void init (void) { instance.set_relaxed (nullptr); } inline void fini (void) @@ -641,15 +648,15 @@ struct hb_lazy_loader_t : hb_data_wrapper_t inline Stored * do_create (void) const { - Stored *p = this->template call_create (); + Stored *p = this->template call_create (); if (unlikely (!p)) - p = const_cast (Subclass::get_null ()); + p = const_cast (Funcs::get_null ()); return p; } static inline void do_destroy (Stored *p) { - if (p && p != Subclass::get_null ()) - Subclass::destroy (p); + if (p && p != Funcs::get_null ()) + Funcs::destroy (p); } inline const Returned * operator -> (void) const { return get (); } @@ -687,8 +694,8 @@ struct hb_lazy_loader_t : hb_data_wrapper_t do_destroy (p); } - inline const Returned * get (void) const { return Subclass::convert (get_stored ()); } - inline Returned * get_unconst (void) const { return const_cast (Subclass::convert (get_stored ())); } + inline const Returned * get (void) const { return Funcs::convert (get_stored ()); } + inline Returned * get_unconst (void) const { return const_cast (Funcs::convert (get_stored ())); } /* To be possibly overloaded by subclasses. */ static inline const Returned* convert (const Stored *p) { return p; } @@ -703,6 +710,13 @@ struct hb_lazy_loader_t : hb_data_wrapper_t p->init (data); return p; } + static inline Stored *create (void) + { + Stored *p = (Stored *) calloc (1, sizeof (Stored)); + if (likely (p)) + p->init (); + return p; + } static inline void destroy (Stored *p) { p->fini (); @@ -717,14 +731,15 @@ struct hb_lazy_loader_t : hb_data_wrapper_t /* Specializations. */ template -struct hb_face_lazy_loader_t : hb_lazy_loader_t, - hb_face_t, WheresFace, - T> {}; +struct hb_face_lazy_loader_t : hb_lazy_loader_t, + hb_face_t, WheresFace> {}; template -struct hb_table_lazy_loader_t : hb_lazy_loader_t, +struct hb_table_lazy_loader_t : hb_lazy_loader_t, hb_face_t, WheresFace, - T, hb_blob_t> + hb_blob_t> { static inline hb_blob_t *create (hb_face_t *face) { @@ -750,9 +765,7 @@ struct hb_table_lazy_loader_t : hb_lazy_loader_t -struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t +struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t { static inline void destroy (hb_font_funcs_t *p) { @@ -764,9 +777,7 @@ struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t -struct hb_unicode_funcs_lazy_loader_t : hb_lazy_loader_t +struct hb_unicode_funcs_lazy_loader_t : hb_lazy_loader_t { static inline void destroy (hb_unicode_funcs_t *p) { -- GitLab