[bit-set] Merge page_for_insert() into page_for()

This commit is contained in:
Behdad Esfahbod 2021-08-18 21:05:21 -06:00
parent f0c3804fa2
commit 48ad9eef1e
1 changed files with 11 additions and 16 deletions

View File

@ -121,7 +121,7 @@ struct hb_bit_set_t
if (unlikely (!successful)) return; if (unlikely (!successful)) return;
if (unlikely (g == INVALID)) return; if (unlikely (g == INVALID)) return;
dirty (); dirty ();
page_t *page = page_for_insert (g); if (unlikely (!page)) return; page_t *page = page_for (g, true); if (unlikely (!page)) return;
page->add (g); page->add (g);
} }
bool add_range (hb_codepoint_t a, hb_codepoint_t b) bool add_range (hb_codepoint_t a, hb_codepoint_t b)
@ -133,21 +133,21 @@ struct hb_bit_set_t
unsigned int mb = get_major (b); unsigned int mb = get_major (b);
if (ma == mb) if (ma == mb)
{ {
page_t *page = page_for_insert (a); if (unlikely (!page)) return false; page_t *page = page_for (a, true); if (unlikely (!page)) return false;
page->add_range (a, b); page->add_range (a, b);
} }
else else
{ {
page_t *page = page_for_insert (a); if (unlikely (!page)) return false; page_t *page = page_for (a, true); if (unlikely (!page)) return false;
page->add_range (a, major_start (ma + 1) - 1); page->add_range (a, major_start (ma + 1) - 1);
for (unsigned int m = ma + 1; m < mb; m++) for (unsigned int m = ma + 1; m < mb; m++)
{ {
page = page_for_insert (major_start (m)); if (unlikely (!page)) return false; page = page_for (major_start (m), true); if (unlikely (!page)) return false;
page->init1 (); page->init1 ();
} }
page = page_for_insert (b); if (unlikely (!page)) return false; page = page_for (b, true); if (unlikely (!page)) return false;
page->add_range (major_start (mb), b); page->add_range (major_start (mb), b);
} }
return true; return true;
@ -163,7 +163,7 @@ struct hb_bit_set_t
while (count) while (count)
{ {
unsigned int m = get_major (g); unsigned int m = get_major (g);
page_t *page = page_for_insert (g); if (unlikely (!page)) return; page_t *page = page_for (g, true); if (unlikely (!page)) return;
unsigned int start = major_start (m); unsigned int start = major_start (m);
unsigned int end = major_start (m + 1); unsigned int end = major_start (m + 1);
do do
@ -192,7 +192,7 @@ struct hb_bit_set_t
while (count) while (count)
{ {
unsigned int m = get_major (g); unsigned int m = get_major (g);
page_t *page = page_for_insert (g); if (unlikely (!page)) return false; page_t *page = page_for (g, true); if (unlikely (!page)) return false;
unsigned int end = major_start (m + 1); unsigned int end = major_start (m + 1);
do do
{ {
@ -743,12 +743,15 @@ struct hb_bit_set_t
protected: protected:
page_t *page_for_insert (hb_codepoint_t g) page_t *page_for (hb_codepoint_t g, bool insert = false)
{ {
page_map_t map = {get_major (g), pages.length}; page_map_t map = {get_major (g), pages.length};
unsigned int i; unsigned int i;
if (!page_map.bfind (map, &i, HB_NOT_FOUND_STORE_CLOSEST)) if (!page_map.bfind (map, &i, HB_NOT_FOUND_STORE_CLOSEST))
{ {
if (!insert)
return nullptr;
if (!resize (pages.length + 1)) if (!resize (pages.length + 1))
return nullptr; return nullptr;
@ -760,14 +763,6 @@ struct hb_bit_set_t
} }
return &pages[page_map[i].index]; return &pages[page_map[i].index];
} }
page_t *page_for (hb_codepoint_t g)
{
page_map_t key = {get_major (g)};
const page_map_t *found = page_map.bsearch (key);
if (found)
return &pages[found->index];
return nullptr;
}
const page_t *page_for (hb_codepoint_t g) const const page_t *page_for (hb_codepoint_t g) const
{ {
page_map_t key = {get_major (g)}; page_map_t key = {get_major (g)};