AK: StringBuilder should prefer to use its inline capacity first

Previously StringBuilder would start allocating an external buffer
once the caller has used up more than half of the inline buffer's
capacity. Instead we should prefer to use the inline buffer until
it is full and only then start to allocate an external buffer.
This commit is contained in:
Gunnar Beutner 2021-05-18 21:27:07 +02:00 committed by Andreas Kling
parent 076018b74b
commit 598d7f4127

View file

@ -22,7 +22,9 @@ inline void StringBuilder::will_append(size_t size)
needed_capacity += size;
VERIFY(!needed_capacity.has_overflow());
Checked<size_t> expanded_capacity = needed_capacity;
expanded_capacity *= 2;
// Prefer to completely use the inline buffer first
if (needed_capacity > inline_capacity)
expanded_capacity *= 2;
VERIFY(!expanded_capacity.has_overflow());
m_buffer.grow(expanded_capacity.value());
}