diff --git a/src/OT/Layout/Common/CoverageFormat2.hh b/src/OT/Layout/Common/CoverageFormat2.hh index 5d467c8a7..02fd29b24 100644 --- a/src/OT/Layout/Common/CoverageFormat2.hh +++ b/src/OT/Layout/Common/CoverageFormat2.hh @@ -139,6 +139,19 @@ struct CoverageFormat2_4 return false; } + static void add_intersected_bits (hb_set_t &set, hb_codepoint_t base, uint64_t bits) + { set.add_bits (base, bits); } + + template + static void add_intersected_bits (IterableOut&& out, hb_codepoint_t base, uint64_t bits) + { + while (bits) + { + out << base + hb_ctz (bits); + bits &= bits - 1; + } + } + template void intersect_set (const hb_set_t &glyphs, IterableOut&& intersect_glyphs) const @@ -161,11 +174,7 @@ struct CoverageFormat2_4 unsigned int end = last - cursor; if (end < hb_bit_page_t::ELT_BITS - 1) bits &= (uint64_t (1) << (end + 1)) - 1; - while (bits) - { - intersect_glyphs << cursor + hb_ctz (bits); - bits &= bits - 1; - } + add_intersected_bits (intersect_glyphs, cursor, bits); } } } diff --git a/src/hb-bit-page.hh b/src/hb-bit-page.hh index 16d5886a2..4087d6eec 100644 --- a/src/hb-bit-page.hh +++ b/src/hb-bit-page.hh @@ -135,7 +135,9 @@ struct hb_bit_page_t } void add (hb_codepoint_t g) { elt (g) |= mask (g); dirty (); } + void add_bits (hb_codepoint_t g, uint64_t bits) { elt (g) |= bits; dirty (); } void del (hb_codepoint_t g) { elt (g) &= ~mask (g); dirty (); } + void del_bits (hb_codepoint_t g, uint64_t bits) { elt (g) &= ~bits; dirty (); } void set (hb_codepoint_t g, bool value) { if (value) add (g); else del (g); } bool get (hb_codepoint_t g) const { return elt (g) & mask (g); } bool may_have (hb_codepoint_t g) const { return get (g); } diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index bb71105b0..089c73c2c 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -113,6 +113,8 @@ struct hb_bit_set_invertible_t void add (hb_codepoint_t g) { unlikely (inverted) ? s.del (g) : s.add (g); } + void add_bits (hb_codepoint_t g, uint64_t bits) + { unlikely (inverted) ? s.del_bits (g, bits) : s.add_bits (g, bits); } bool add_range (hb_codepoint_t a, hb_codepoint_t b) { return unlikely (inverted) ? ((void) s.del_range (a, b), true) : s.add_range (a, b); } diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 25313e40a..edf8add28 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -161,6 +161,14 @@ struct hb_bit_set_t page_t *page = page_for (g, true); if (unlikely (!page)) return; page->add (g); } + void add_bits (hb_codepoint_t g, uint64_t bits) + { + if (unlikely (!successful) || unlikely (!bits)) return; + assert (!(g & (page_t::ELT_BITS - 1))); + dirty (); + page_t *page = page_for (g, true); if (unlikely (!page)) return; + page->add_bits (g, bits); + } bool add_range (hb_codepoint_t a, hb_codepoint_t b) { if (unlikely (!successful)) return true; /* https://github.com/harfbuzz/harfbuzz/issues/657 */ @@ -291,6 +299,16 @@ struct hb_bit_set_t dirty (); page->del (g); } + void del_bits (hb_codepoint_t g, uint64_t bits) + { + if (unlikely (!successful) || unlikely (!bits)) return; + assert (!(g & (page_t::ELT_BITS - 1))); + page_t *page = page_for (g); + if (!page) + return; + dirty (); + page->del_bits (g, bits); + } private: void del_pages (int ds, int de) diff --git a/src/hb-set.hh b/src/hb-set.hh index 5c8601fcd..b9ef5df23 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -87,6 +87,7 @@ struct hb_sparseset_t uint32_t hash () const { return s.hash (); } void add (hb_codepoint_t g) { s.add (g); } + void add_bits (hb_codepoint_t g, uint64_t bits) { s.add_bits (g, bits); } bool add_range (hb_codepoint_t first, hb_codepoint_t last) { return s.add_range (first, last); } template diff --git a/src/test-set.cc b/src/test-set.cc index f47fbaaa5..01284cb8a 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -178,6 +178,20 @@ main (int argc, char **argv) hb_always_assert (!s.get_singleton (&singleton)); } + /* Test word-at-a-time insertion. */ + { + hb_set_t s; + s.add_bits (64, uint64_t (1) | (uint64_t (1) << 63)); + hb_always_assert (s.get_population () == 2); + hb_always_assert (s.has (64)); + hb_always_assert (s.has (127)); + + s.invert (); + s.add_bits (64, uint64_t (1) | (uint64_t (1) << 63)); + hb_always_assert (s.has (64)); + hb_always_assert (s.has (127)); + } + /* Adding HB_SET_VALUE_INVALID */ { hb_set_t s;