This commit is contained in:
Behdad Esfahbod 2018-02-10 13:25:49 -06:00
parent 570d523761
commit af274507c4
1 changed files with 6 additions and 9 deletions

View File

@ -425,14 +425,13 @@ struct hb_prealloced_array_t
return &array[len - 1]; return &array[len - 1];
} }
// Alloc enouch for size if size < allocated. Don't adjust len. /* Allocate for size but don't adjust len. */
inline bool alloc(unsigned int size) inline bool alloc(unsigned int size)
{ {
if (likely (size <= allocated)) if (likely (size <= allocated))
{
return true; return true;
}
/* Need to reallocate */ /* Reallocate */
unsigned int new_allocated = allocated; unsigned int new_allocated = allocated;
while (size >= new_allocated) while (size >= new_allocated)
@ -456,16 +455,14 @@ struct hb_prealloced_array_t
array = new_array; array = new_array;
allocated = new_allocated; allocated = new_allocated;
return true; return true;
} }
inline bool resize (unsigned int size) inline bool resize (unsigned int size)
{ {
if (!alloc(size)) if (!alloc (size))
{
return false; return false;
}
len = size; len = size;
return true; return true;