From bc33b87f5e72648c66949cc9469291e77aa80701 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 9 Jun 2021 11:51:32 -0600 Subject: [PATCH] [set] Use references, not pointers, in internal C++ API --- src/hb-ot-layout-gsubgpos.hh | 2 +- src/hb-set.cc | 14 ++++---- src/hb-set.hh | 69 ++++++++++++++++++------------------ src/hb-subset-plan.cc | 2 +- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index b537ba005..fb86311f3 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -122,7 +122,7 @@ struct hb_closure_context_t : hb_set_t *covered_glyph_set = done_lookups_glyph_set->get (lookup_index); if (unlikely (covered_glyph_set->in_error ())) return true; - if (parent_active_glyphs ()->is_subset (covered_glyph_set)) + if (parent_active_glyphs ()->is_subset (*covered_glyph_set)) return true; hb_set_union (covered_glyph_set, parent_active_glyphs ()); diff --git a/src/hb-set.cc b/src/hb-set.cc index 86bf70034..d75e57fd7 100644 --- a/src/hb-set.cc +++ b/src/hb-set.cc @@ -309,7 +309,7 @@ hb_bool_t hb_set_is_equal (const hb_set_t *set, const hb_set_t *other) { - return set->is_equal (other); + return set->is_equal (*other); } /** @@ -327,7 +327,7 @@ hb_bool_t hb_set_is_subset (const hb_set_t *set, const hb_set_t *larger_set) { - return set->is_subset (larger_set); + return set->is_subset (*larger_set); } /** @@ -343,7 +343,7 @@ void hb_set_set (hb_set_t *set, const hb_set_t *other) { - set->set (other); + set->set (*other); } /** @@ -359,7 +359,7 @@ void hb_set_union (hb_set_t *set, const hb_set_t *other) { - set->union_ (other); + set->union_ (*other); } /** @@ -375,7 +375,7 @@ void hb_set_intersect (hb_set_t *set, const hb_set_t *other) { - set->intersect (other); + set->intersect (*other); } /** @@ -391,7 +391,7 @@ void hb_set_subtract (hb_set_t *set, const hb_set_t *other) { - set->subtract (other); + set->subtract (*other); } /** @@ -408,7 +408,7 @@ void hb_set_symmetric_difference (hb_set_t *set, const hb_set_t *other) { - set->symmetric_difference (other); + set->symmetric_difference (*other); } #ifndef HB_DISABLE_DEPRECATED diff --git a/src/hb-set.hh b/src/hb-set.hh index 8d0926705..ec247d8cc 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -43,9 +43,10 @@ struct hb_set_t hb_set_t () { init (); } ~hb_set_t () { fini (); } - hb_set_t (const hb_set_t& other) : hb_set_t () { set (&other); } - void operator= (const hb_set_t& other) { set (&other); } + hb_set_t (const hb_set_t& other) : hb_set_t () { set (other); } + void operator= (const hb_set_t& other) { set (other); } // TODO Add move construtor/assign + // TODO Add constructor for Iterator; with specialization for (sorted) vector / array? struct page_map_t { @@ -480,32 +481,32 @@ struct hb_set_t hb_codepoint_t c = first - 1; return next (&c) && c <= last; } - void set (const hb_set_t *other) + void set (const hb_set_t &other) { if (unlikely (!successful)) return; - unsigned int count = other->pages.length; + unsigned int count = other.pages.length; if (!resize (count)) return; - population = other->population; - memcpy ((void *) pages, (const void *) other->pages, count * pages.item_size); - memcpy ((void *) page_map, (const void *) other->page_map, count * page_map.item_size); + population = other.population; + memcpy ((void *) pages, (const void *) other.pages, count * pages.item_size); + memcpy ((void *) page_map, (const void *) other.page_map, count * page_map.item_size); } - bool is_equal (const hb_set_t *other) const + bool is_equal (const hb_set_t &other) const { - if (get_population () != other->get_population ()) + if (get_population () != other.get_population ()) return false; unsigned int na = pages.length; - unsigned int nb = other->pages.length; + unsigned int nb = other.pages.length; unsigned int a = 0, b = 0; for (; a < na && b < nb; ) { if (page_at (a).is_empty ()) { a++; continue; } - if (other->page_at (b).is_empty ()) { b++; continue; } - if (page_map[a].major != other->page_map[b].major || - !page_at (a).is_equal (other->page_at (b))) + if (other.page_at (b).is_empty ()) { b++; continue; } + if (page_map[a].major != other.page_map[b].major || + !page_at (a).is_equal (other.page_at (b))) return false; a++; b++; @@ -513,24 +514,24 @@ struct hb_set_t for (; a < na; a++) if (!page_at (a).is_empty ()) { return false; } for (; b < nb; b++) - if (!other->page_at (b).is_empty ()) { return false; } + if (!other.page_at (b).is_empty ()) { return false; } return true; } - bool is_subset (const hb_set_t *larger_set) const + bool is_subset (const hb_set_t &larger_set) const { /* TODO: Merge this and is_equal() into something like process(). */ - if (unlikely(larger_set->is_empty ())) + if (unlikely(larger_set.is_empty ())) return is_empty (); uint32_t spi = 0; - for (uint32_t lpi = 0; spi < page_map.length && lpi < larger_set->page_map.length; lpi++) + for (uint32_t lpi = 0; spi < page_map.length && lpi < larger_set.page_map.length; lpi++) { uint32_t spm = page_map[spi].major; - uint32_t lpm = larger_set->page_map[lpi].major; + uint32_t lpm = larger_set.page_map[lpi].major; auto sp = page_at (spi); - auto lp = larger_set->page_at (lpi); + auto lp = larger_set.page_at (lpi); if (spm < lpm && !sp.is_empty ()) return false; @@ -597,7 +598,7 @@ struct hb_set_t } template - void process (const Op& op, const hb_set_t *other) + void process (const Op& op, const hb_set_t &other) { const bool passthru_left = op (1, 0); const bool passthru_right = op (0, 1); @@ -607,7 +608,7 @@ struct hb_set_t dirty (); unsigned int na = pages.length; - unsigned int nb = other->pages.length; + unsigned int nb = other.pages.length; unsigned int next_page = na; unsigned int count = 0, newCount = 0; @@ -621,7 +622,7 @@ struct hb_set_t for (; a < na && b < nb; ) { - if (page_map[a].major == other->page_map[b].major) + if (page_map[a].major == other.page_map[b].major) { if (!passthru_left) { @@ -638,7 +639,7 @@ struct hb_set_t a++; b++; } - else if (page_map[a].major < other->page_map[b].major) + else if (page_map[a].major < other.page_map[b].major) { if (passthru_left) count++; @@ -673,15 +674,15 @@ struct hb_set_t b = nb; for (; a && b; ) { - if (page_map[a - 1].major == other->page_map[b - 1].major) + if (page_map[a - 1].major == other.page_map[b - 1].major) { a--; b--; count--; page_map[count] = page_map[a]; - page_at (count).v = op (page_at (a).v, other->page_at (b).v); + page_at (count).v = op (page_at (a).v, other.page_at (b).v); } - else if (page_map[a - 1].major > other->page_map[b - 1].major) + else if (page_map[a - 1].major > other.page_map[b - 1].major) { a--; if (passthru_left) @@ -696,9 +697,9 @@ struct hb_set_t if (passthru_right) { count--; - page_map[count].major = other->page_map[b].major; + page_map[count].major = other.page_map[b].major; page_map[count].index = next_page++; - page_at (count).v = other->page_at (b).v; + page_at (count).v = other.page_at (b).v; } } } @@ -714,9 +715,9 @@ struct hb_set_t { b--; count--; - page_map[count].major = other->page_map[b].major; + page_map[count].major = other.page_map[b].major; page_map[count].index = next_page++; - page_at (count).v = other->page_at (b).v; + page_at (count).v = other.page_at (b).v; } assert (!count); if (pages.length > newCount) @@ -726,19 +727,19 @@ struct hb_set_t resize (newCount); } - void union_ (const hb_set_t *other) + void union_ (const hb_set_t &other) { process (hb_bitwise_or, other); } - void intersect (const hb_set_t *other) + void intersect (const hb_set_t &other) { process (hb_bitwise_and, other); } - void subtract (const hb_set_t *other) + void subtract (const hb_set_t &other) { process (hb_bitwise_sub, other); } - void symmetric_difference (const hb_set_t *other) + void symmetric_difference (const hb_set_t &other) { process (hb_bitwise_xor, other); } diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 56d66e117..62137bf8d 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -285,7 +285,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, hb_set_t glyphset_colrv0; if (colr.is_valid ()) { - glyphset_colrv0.union_ (cur_glyphset); + glyphset_colrv0.union_ (*cur_glyphset); for (hb_codepoint_t gid : cur_glyphset->iter ()) colr.closure_glyphs (gid, &glyphset_colrv0); cur_glyphset = &glyphset_colrv0;