From bb905e9afcc3eb28a22ba78c09e661a814d04c1f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 12 Aug 2018 16:40:08 -0700 Subject: [PATCH] [lazy] Minor --- src/hb-machinery-private.hh | 36 ++++++++++++++++++------------------ src/hb-ot-font.cc | 8 ++++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/hb-machinery-private.hh b/src/hb-machinery-private.hh index 193f5ed22..d40f9d9c0 100644 --- a/src/hb-machinery-private.hh +++ b/src/hb-machinery-private.hh @@ -693,7 +693,21 @@ struct hb_lazy_loader_t : hb_data_wrapper_t /* To be possibly overloaded by subclasses. */ static inline const Returned* convert (const Stored *p) { return p; } static inline Returned* convert (Stored *p) { return p; } + + /* By default null/init/fini the object. */ static inline const Stored* get_null (void) { return &Null(Stored); } + static inline Stored *create (Data *data) + { + Stored *p = (Stored *) calloc (1, sizeof (Stored)); + if (likely (p)) + p->init (data); + return p; + } + static inline void destroy (Stored *p) + { + p->fini (); + ::free (p); + } private: /* Must only have one pointer. */ @@ -703,23 +717,9 @@ struct hb_lazy_loader_t : hb_data_wrapper_t /* Specializations. */ template -struct hb_object_lazy_loader_t : hb_lazy_loader_t, +struct hb_face_lazy_loader_t : hb_lazy_loader_t, hb_face_t, WheresFace, - T> -{ - static inline T *create (hb_face_t *face) - { - T *p = (T *) calloc (1, sizeof (T)); - if (likely (p)) - p->init (face); - return p; - } - static inline void destroy (T *p) - { - p->fini (); - free (p); - } -}; + T> {}; template struct hb_table_lazy_loader_t : hb_lazy_loader_t, @@ -751,8 +751,8 @@ struct hb_table_lazy_loader_t : hb_lazy_loader_t struct hb_font_funcs_lazy_loader_t : hb_lazy_loader_t + void, 0, + hb_font_funcs_t> { static inline void destroy (hb_font_funcs_t *p) { diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index cac180950..0b14ff1e2 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -71,10 +71,10 @@ struct hb_ot_font_t OT::vmtx::accelerator_t v_metrics; hb_face_t *face; /* MUST be JUST before the lazy loaders. */ - hb_object_lazy_loader_t<1, OT::glyf::accelerator_t> glyf; - hb_object_lazy_loader_t<2, OT::CBDT::accelerator_t> cbdt; - hb_object_lazy_loader_t<3, OT::post::accelerator_t> post; - hb_object_lazy_loader_t<4, OT::kern::accelerator_t> kern; + hb_face_lazy_loader_t<1, OT::glyf::accelerator_t> glyf; + hb_face_lazy_loader_t<2, OT::CBDT::accelerator_t> cbdt; + hb_face_lazy_loader_t<3, OT::post::accelerator_t> post; + hb_face_lazy_loader_t<4, OT::kern::accelerator_t> kern; };