[set] One more try at fixing clear() on empty set

This commit is contained in:
Behdad Esfahbod 2021-08-24 10:55:12 -06:00
parent fb07f8f876
commit 357976963e
1 changed files with 6 additions and 9 deletions

View File

@ -78,7 +78,8 @@ struct hb_bit_set_t
bool resize (unsigned int count) bool resize (unsigned int count)
{ {
if (unlikely (count > pages.length && !successful)) return false; if (unlikely (!successful)) return false;
if (count <= pages.length) return true;
if (unlikely (!pages.resize (count) || !page_map.resize (count))) if (unlikely (!pages.resize (count) || !page_map.resize (count)))
{ {
pages.resize (page_map.length); pages.resize (page_map.length);
@ -328,7 +329,7 @@ struct hb_bit_set_t
{ {
if (unlikely (!successful)) return; if (unlikely (!successful)) return;
unsigned int count = other.pages.length; unsigned int count = other.pages.length;
if (!resize (count)) if (unlikely (!resize (count)))
return; return;
population = other.population; population = other.population;
@ -508,7 +509,7 @@ struct hb_bit_set_t
compact (compact_workspace, write_index); compact (compact_workspace, write_index);
} }
if (!resize (count)) if (unlikely (!resize (count)))
return; return;
newCount = count; newCount = count;
@ -564,10 +565,6 @@ struct hb_bit_set_t
page_at (count).v = other.page_at (b).v; page_at (count).v = other.page_at (b).v;
} }
assert (!count); assert (!count);
if (pages.length > newCount)
// This resize() doesn't need to be checked because we can't get here
// if the set is currently in_error() and this only resizes downwards
// which will always succeed if the set is not in_error().
resize (newCount); resize (newCount);
} }
@ -782,7 +779,7 @@ struct hb_bit_set_t
if (!insert) if (!insert)
return nullptr; return nullptr;
if (!resize (pages.length + 1)) if (unlikely (!resize (pages.length + 1)))
return nullptr; return nullptr;
pages[map.index].init0 (); pages[map.index].init0 ();