[vector] Construct items when enlarging
This commit is contained in:
parent
813eaba6ea
commit
7171917b52
|
@ -232,6 +232,26 @@ struct hb_vector_t
|
|||
return new_array;
|
||||
}
|
||||
|
||||
template <typename T = Type,
|
||||
hb_enable_if (std::is_trivially_copy_assignable<T>::value)>
|
||||
void
|
||||
grow_vector (unsigned size)
|
||||
{
|
||||
memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ));
|
||||
length = size;
|
||||
}
|
||||
template <typename T = Type,
|
||||
hb_enable_if (!std::is_trivially_copy_assignable<T>::value)>
|
||||
void
|
||||
grow_vector (unsigned size)
|
||||
{
|
||||
while (length < size)
|
||||
{
|
||||
length++;
|
||||
new (std::addressof (arrayZ[length - 1])) Type ();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T = Type,
|
||||
hb_enable_if (std::is_trivially_copy_assignable<T>::value)>
|
||||
void
|
||||
|
@ -294,8 +314,7 @@ struct hb_vector_t
|
|||
return false;
|
||||
|
||||
if (size > length)
|
||||
// XXX construct objects.
|
||||
memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ));
|
||||
grow_vector (size);
|
||||
else if (size < length)
|
||||
shrink_vector (size);
|
||||
|
||||
|
|
Loading…
Reference in New Issue