From 4d19c724c0423892810eefe8b9d9c6efcf274ddd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 3 Dec 2022 09:57:29 -0700 Subject: [PATCH] [CoverageFormat1] Speed up intersects() Speeds up SourceHanSerif/10000 benchmark (not in test suite) by 32%! --- src/OT/Layout/Common/CoverageFormat1.hh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/OT/Layout/Common/CoverageFormat1.hh b/src/OT/Layout/Common/CoverageFormat1.hh index adc511e9d..5d68e3d15 100644 --- a/src/OT/Layout/Common/CoverageFormat1.hh +++ b/src/OT/Layout/Common/CoverageFormat1.hh @@ -77,9 +77,14 @@ struct CoverageFormat1_3 bool intersects (const hb_set_t *glyphs) const { - /* TODO Speed up, using hb_set_next() and bsearch()? - * Experience with other tables suggest that it would - * not speed up though. */ + if (glyphArray.len > glyphs->get_population () * hb_bit_storage ((unsigned) glyphArray.len) / 2) + { + for (hb_codepoint_t g = HB_SET_VALUE_INVALID; glyphs->next (&g);) + if (get_coverage (g) != NOT_COVERED) + return true; + return false; + } + for (const auto& g : glyphArray.as_array ()) if (glyphs->has (g)) return true;