diff options
Diffstat (limited to 'src/hb-bit-set.hh')
-rw-r--r-- | src/hb-bit-set.hh | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 8de6e037f..a63887efd 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -85,10 +85,10 @@ struct hb_bit_set_t void err () { if (successful) successful = false; } /* TODO Remove */ bool in_error () const { return !successful; } - bool resize (unsigned int count, bool clear = true) + bool resize (unsigned int count) { if (unlikely (!successful)) return false; - if (unlikely (!pages.resize (count, clear) || !page_map.resize (count, clear))) + if (unlikely (!pages.resize (count) || !page_map.resize (count))) { pages.resize (page_map.length); successful = false; @@ -330,8 +330,10 @@ struct hb_bit_set_t } /* Has interface. */ - bool operator [] (hb_codepoint_t k) const { return get (k); } - bool has (hb_codepoint_t k) const { return (*this)[k]; } + static constexpr bool SENTINEL = false; + typedef bool value_t; + value_t operator [] (hb_codepoint_t k) const { return get (k); } + bool has (hb_codepoint_t k) const { return (*this)[k] != SENTINEL; } /* Predicate. */ bool operator () (hb_codepoint_t k) const { return has (k); } @@ -350,7 +352,7 @@ struct hb_bit_set_t { if (unlikely (!successful)) return; unsigned int count = other.pages.length; - if (unlikely (!resize (count, false))) + if (unlikely (!resize (count))) return; population = other.population; @@ -389,7 +391,7 @@ struct hb_bit_set_t bool is_subset (const hb_bit_set_t &larger_set) const { if (has_population () && larger_set.has_population () && - population > larger_set.population) + population != larger_set.population) return false; uint32_t spi = 0; @@ -538,21 +540,21 @@ struct hb_bit_set_t b = nb; for (; a && b; ) { - if (page_map.arrayZ[a - 1].major == other.page_map.arrayZ[b - 1].major) + if (page_map[a - 1].major == other.page_map[b - 1].major) { a--; b--; count--; - page_map.arrayZ[count] = page_map.arrayZ[a]; + page_map[count] = page_map[a]; page_at (count).v = op (page_at (a).v, other.page_at (b).v); } - else if (page_map.arrayZ[a - 1].major > other.page_map.arrayZ[b - 1].major) + else if (page_map[a - 1].major > other.page_map[b - 1].major) { a--; if (passthru_left) { count--; - page_map.arrayZ[count] = page_map.arrayZ[a]; + page_map[count] = page_map[a]; } } else @@ -561,8 +563,8 @@ struct hb_bit_set_t if (passthru_right) { count--; - page_map.arrayZ[count].major = other.page_map.arrayZ[b].major; - page_map.arrayZ[count].index = next_page++; + page_map[count].major = other.page_map[b].major; + page_map[count].index = next_page++; page_at (count).v = other.page_at (b).v; } } @@ -572,15 +574,15 @@ struct hb_bit_set_t { a--; count--; - page_map.arrayZ[count] = page_map.arrayZ[a]; + page_map[count] = page_map [a]; } if (passthru_right) while (b) { b--; count--; - page_map.arrayZ[count].major = other.page_map.arrayZ[b].major; - page_map.arrayZ[count].index = next_page++; + page_map[count].major = other.page_map[b].major; + page_map[count].index = next_page++; page_at (count).v = other.page_at (b).v; } assert (!count); @@ -603,6 +605,8 @@ struct hb_bit_set_t bool next (hb_codepoint_t *codepoint) const { + // TODO: this should be merged with prev() as both implementations + // are very similar. if (unlikely (*codepoint == INVALID)) { *codepoint = get_min (); return *codepoint != INVALID; @@ -636,7 +640,7 @@ struct hb_bit_set_t for (; i < page_map.length; i++) { - const page_map_t ¤t = page_map_array[i]; + const page_map_t ¤t = page_map.arrayZ[i]; hb_codepoint_t m = pages_array[current.index].get_min (); if (m != INVALID) { @@ -659,21 +663,21 @@ struct hb_bit_set_t page_map_t map = {get_major (*codepoint), 0}; unsigned int i; page_map.bfind (map, &i, HB_NOT_FOUND_STORE_CLOSEST); - if (i < page_map.length && page_map.arrayZ[i].major == map.major) + if (i < page_map.length && page_map[i].major == map.major) { - if (pages[page_map.arrayZ[i].index].previous (codepoint)) + if (pages[page_map[i].index].previous (codepoint)) { - *codepoint += page_map.arrayZ[i].major * page_t::PAGE_BITS; + *codepoint += page_map[i].major * page_t::PAGE_BITS; return true; } } i--; for (; (int) i >= 0; i--) { - hb_codepoint_t m = pages.arrayZ[page_map.arrayZ[i].index].get_max (); + hb_codepoint_t m = pages[page_map[i].index].get_max (); if (m != INVALID) { - *codepoint = page_map.arrayZ[i].major * page_t::PAGE_BITS + m; + *codepoint = page_map[i].major * page_t::PAGE_BITS + m; return true; } } @@ -901,7 +905,7 @@ struct hb_bit_set_t { auto &cached_page = page_map.arrayZ[i]; if (cached_page.major == major) - return &pages.arrayZ[cached_page.index]; + return &pages[cached_page.index]; } page_map_t map = {major, pages.length}; @@ -913,15 +917,15 @@ struct hb_bit_set_t if (unlikely (!resize (pages.length + 1))) return nullptr; - pages.arrayZ[map.index].init0 (); - memmove (page_map.arrayZ + i + 1, - page_map.arrayZ + i, + pages[map.index].init0 (); + memmove (page_map + i + 1, + page_map + i, (page_map.length - 1 - i) * page_map.item_size); page_map[i] = map; } last_page_lookup = i; - return &pages.arrayZ[page_map.arrayZ[i].index]; + return &pages[page_map[i].index]; } const page_t *page_for (hb_codepoint_t g) const { @@ -935,7 +939,7 @@ struct hb_bit_set_t { auto &cached_page = page_map.arrayZ[i]; if (cached_page.major == major) - return &pages.arrayZ[cached_page.index]; + return &pages[cached_page.index]; } page_map_t key = {major}; @@ -943,18 +947,10 @@ struct hb_bit_set_t return nullptr; last_page_lookup = i; - return &pages.arrayZ[page_map[i].index]; - } - page_t &page_at (unsigned int i) - { - assert (i < page_map.length); - return pages.arrayZ[page_map.arrayZ[i].index]; - } - const page_t &page_at (unsigned int i) const - { - assert (i < page_map.length); - return pages.arrayZ[page_map.arrayZ[i].index]; + return &pages[page_map[i].index]; } + page_t &page_at (unsigned int i) { return pages[page_map[i].index]; } + const page_t &page_at (unsigned int i) const { return pages[page_map[i].index]; } unsigned int get_major (hb_codepoint_t g) const { return g >> page_t::PAGE_BITS_LOG_2; } unsigned int page_remainder (hb_codepoint_t g) const { return g & page_t::PAGE_BITMASK; } hb_codepoint_t major_start (unsigned int major) const { return major << page_t::PAGE_BITS_LOG_2; } |