[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;
|
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,
|
template <typename T = Type,
|
||||||
hb_enable_if (std::is_trivially_copy_assignable<T>::value)>
|
hb_enable_if (std::is_trivially_copy_assignable<T>::value)>
|
||||||
void
|
void
|
||||||
|
@ -294,8 +314,7 @@ struct hb_vector_t
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (size > length)
|
if (size > length)
|
||||||
// XXX construct objects.
|
grow_vector (size);
|
||||||
memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ));
|
|
||||||
else if (size < length)
|
else if (size < length)
|
||||||
shrink_vector (size);
|
shrink_vector (size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue