Simplify hb_prealloced_array_t initialization

This commit is contained in:
Behdad Esfahbod 2017-10-15 16:38:29 -04:00
parent 7737e87ac4
commit 56ef4e0c52
1 changed files with 7 additions and 6 deletions

View File

@ -404,7 +404,12 @@ struct hb_prealloced_array_t
Type *array; Type *array;
Type static_array[StaticSize]; Type static_array[StaticSize];
void init (void) { memset (this, 0, sizeof (*this)); } void init (void)
{
len = 0;
allocated = ARRAY_LENGTH (static_array);
array = static_array;
}
inline Type& operator [] (unsigned int i) { return array[i]; } inline Type& operator [] (unsigned int i) { return array[i]; }
inline const Type& operator [] (unsigned int i) const { return array[i]; } inline const Type& operator [] (unsigned int i) const { return array[i]; }
@ -419,11 +424,7 @@ struct hb_prealloced_array_t
inline bool resize (unsigned int size) inline bool resize (unsigned int size)
{ {
if (!array) { if (unlikely (size > allocated))
array = static_array;
allocated = ARRAY_LENGTH (static_array);
}
if (size > allocated)
{ {
/* Need to reallocate */ /* Need to reallocate */