[vector] Add "initialize" argument to resize()

This commit is contained in:
Behdad Esfahbod 2022-11-22 10:20:11 -07:00
parent a2059f8f55
commit b0d2641186
1 changed files with 9 additions and 3 deletions

View File

@ -351,16 +351,22 @@ struct hb_vector_t
return true; return true;
} }
bool resize (int size_) bool resize (int size_, bool initialize = true)
{ {
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_; unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;
if (!alloc (size)) if (!alloc (size))
return false; return false;
if (size > length) if (size > length)
grow_vector (size); {
if (initialize)
grow_vector (size);
}
else if (size < length) else if (size < length)
shrink_vector (size); {
if (initialize)
shrink_vector (size);
}
length = size; length = size;
return true; return true;