[vector] Minor micro-optimize shrink_vector

The compiler seems to understand this pattern better.
This commit is contained in:
Behdad Esfahbod 2023-06-27 06:56:00 -06:00
parent aed215639a
commit 3edd6cdcd5

View file

@ -374,14 +374,15 @@ struct hb_vector_t
void
shrink_vector (unsigned size)
{
if (std::is_trivially_destructible<Type>::value)
length = size;
else
while ((unsigned) length > size)
{
arrayZ[(unsigned) length - 1].~Type ();
length--;
}
assert (size <= length);
if (!std::is_trivially_destructible<Type>::value)
{
unsigned count = length - size;
Type *p = arrayZ + length - 1;
while (count--)
p--->~Type ();
}
length = size;
}
void