[set] Don't discard allocation in operator=

That had caused memory thrashing.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54789
pull/4004/head
Behdad Esfahbod 2 years ago
parent e6bbf112ea
commit 6c272b920d
  1. 10
      src/hb-bit-set.hh

@ -38,7 +38,7 @@ struct hb_bit_set_t
hb_bit_set_t () = default;
~hb_bit_set_t () = default;
hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other); }
hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other, true); }
hb_bit_set_t ( hb_bit_set_t&& other) : hb_bit_set_t () { hb_swap (*this, other); }
hb_bit_set_t& operator= (const hb_bit_set_t& other) { set (other); return *this; }
hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; }
@ -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, bool clear = true, bool exact_size = false)
{
if (unlikely (!successful)) return false;
if (unlikely (!pages.resize (count, clear, true) || !page_map.resize (count, clear, true)))
if (unlikely (!pages.resize (count, clear, exact_size) || !page_map.resize (count, clear, exact_size)))
{
pages.resize (page_map.length);
successful = false;
@ -346,11 +346,11 @@ struct hb_bit_set_t
hb_codepoint_t c = first - 1;
return next (&c) && c <= last;
}
void set (const hb_bit_set_t &other)
void set (const hb_bit_set_t &other, bool exact_size = false)
{
if (unlikely (!successful)) return;
unsigned int count = other.pages.length;
if (unlikely (!resize (count, false)))
if (unlikely (!resize (count, false, exact_size)))
return;
population = other.population;

Loading…
Cancel
Save