From 68964efa553e77e0867777f4c4bfa5e962a9bda6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 11 Dec 2022 13:21:01 -0700 Subject: [PATCH] [COLR] Use bsearch in get_extents --- src/hb-ot-color-colr-table.hh | 11 ++++++++--- src/hb-static.cc | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 2fcf7afa6..56ebb2841 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -953,6 +953,9 @@ struct ClipBox struct ClipRecord { + int cmp (hb_codepoint_t g) const + { return g < startGlyphID ? -1 : g <= endGlyphID ? 0 : +1; } + ClipRecord* copy (hb_serialize_context_t *c, const void *base) const { TRACE_SERIALIZE (this); @@ -980,6 +983,7 @@ struct ClipRecord public: DEFINE_SIZE_STATIC (7); }; +DECLARE_NULL_NAMESPACE_BYTES (OT, ClipRecord); struct ClipList { @@ -1075,10 +1079,11 @@ struct ClipList bool get_extents (hb_codepoint_t gid, hb_glyph_extents_t *extents) const { - for (auto& record : clips) + auto *rec = clips.as_array ().bsearch (gid); + if (rec) { - if (record.startGlyphID <= gid && gid <= record.endGlyphID) - return record.get_extents (extents, this); + rec->get_extents (extents, this); + return true; } return false; } diff --git a/src/hb-static.cc b/src/hb-static.cc index 5d4c7cda1..eac50754c 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -33,6 +33,7 @@ #include "hb-aat-layout-feat-table.hh" #include "hb-ot-layout-common.hh" #include "hb-ot-cmap-table.hh" +#include "hb-ot-color-colr-table.hh" #include "hb-ot-glyf-table.hh" #include "hb-ot-head-table.hh" #include "hb-ot-maxp-table.hh" @@ -47,6 +48,7 @@ DEFINE_NULL_NAMESPACE_BYTES (OT, Index) = {0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, VarIdx) = {0xFF,0xFF,0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (OT, LangSys) = {0x00,0x00, 0xFF,0xFF, 0x00,0x00}; DEFINE_NULL_NAMESPACE_BYTES (OT, RangeRecord) = {0x01}; +DEFINE_NULL_NAMESPACE_BYTES (OT, ClipRecord) = {0x01}; DEFINE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup) = {0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00}; DEFINE_NULL_NAMESPACE_BYTES (AAT, SettingName) = {0xFF,0xFF, 0xFF,0xFF}; DEFINE_NULL_NAMESPACE_BYTES (AAT, Lookup) = {0xFF,0xFF};