From dc4225ccd1d16a1139cbc6092353db9ed03e8980 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 Nov 2018 20:48:46 -0500 Subject: [PATCH] Don't retry creating again and again in lazy_loader if create failed Still does that if get_null() returns nullptr. Our shaper data objects are like that. Shrug. --- src/hb-machinery.hh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index ce6c94535..ffc9627fd 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -752,16 +752,19 @@ struct hb_data_wrapper_t return *(((Data **) (void *) this) - WheresData); } + inline bool is_inert (void) const { return !get_data (); } + template inline Stored * call_create (void) const { - Data *data = this->get_data (); - return likely (data) ? Subclass::create (data) : nullptr; + return Subclass::create (this->get_data ()); } }; template <> struct hb_data_wrapper_t { + inline bool is_inert (void) const { return false; } + template inline Stored * call_create (void) const { @@ -800,7 +803,7 @@ struct hb_lazy_loader_t : hb_data_wrapper_t static inline void do_destroy (Stored *p) { - if (p) + if (p && p != const_cast (Funcs::get_null ())) Funcs::destroy (p); } @@ -814,9 +817,12 @@ struct hb_lazy_loader_t : hb_data_wrapper_t Stored *p = this->instance.get (); if (unlikely (!p)) { + if (unlikely (this->is_inert ())) + return const_cast (Funcs::get_null ()); + p = this->template call_create (); if (unlikely (!p)) - return const_cast (Funcs::get_null ()); + p = const_cast (Funcs::get_null ()); if (unlikely (!this->instance.cmpexch (nullptr, p))) {