From cf8f00e3548c4e4eb8dca7da598bfe9990b53dd3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 20 May 2022 17:14:10 -0600 Subject: [PATCH] [VarStore] Don't use NAN Is faster. With this, I'm seeing 25 to 28% speedup in glyph_h_advances benchmark of benchmark-font for var/hb tests. --- src/hb-ot-layout-common.hh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index e4f3e06f7..61d0cf14f 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -2601,6 +2601,8 @@ struct VarRegionAxis DEFINE_SIZE_STATIC (6); }; +#define REGION_CACHE_ITEM_CACHE_INVALID 2.f + struct VarRegionList { using cache_t = float; @@ -2616,7 +2618,7 @@ struct VarRegionList if (cache) { cached = &(cache[region_index]); - if (!std::isnan (*cached)) + if (*cached != REGION_CACHE_ITEM_CACHE_INVALID) return *cached; } @@ -2875,8 +2877,10 @@ struct VariationStore float *cache = (float *) hb_malloc (sizeof (float) * count); if (unlikely (!cache)) return nullptr; + for (unsigned i = 0; i < count; i++) - cache[i] = NAN; + cache[i] = REGION_CACHE_ITEM_CACHE_INVALID; + return cache; } @@ -3035,6 +3039,8 @@ struct VariationStore DEFINE_SIZE_ARRAY_SIZED (8, dataSets); }; +#undef REGION_CACHE_ITEM_CACHE_INVALID + /* * Feature Variations */