From 4d4fd64ff47da04a7008d410c92e8fb4ad970781 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Nov 2018 18:07:36 -0500 Subject: [PATCH] Allow non-nullable OffsetTo<> to non-Null'able objects --- src/hb-open-type.hh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 0ecd3c6b6..f4a9a5e87 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -231,17 +231,31 @@ struct FixedVersion * Use: (base+offset) */ +template +struct _hb_has_null +{ + static inline const Type *get_null (void) { return nullptr; } + static inline Type *get_crap (void) { return nullptr; } +}; +template +struct _hb_has_null +{ + static inline const Type *get_null (void) { return &Null(Type); } + static inline Type *get_crap (void) { return &Crap(Type); } +}; + template struct OffsetTo : Offset { inline const Type& operator () (const void *base) const { - if (unlikely (this->is_null ())) return Null (Type); + if (unlikely (this->is_null ())) return *_hb_has_null::get_null (); return StructAtOffset (base, *this); } inline Type& operator () (void *base) const { if (unlikely (this->is_null ())) return Crap (Type); + if (unlikely (this->is_null ())) return *_hb_has_null::get_crap (); return StructAtOffset (base, *this); }