mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-02 16:25:34 +03:00
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:
parent
076018b74b
commit
598d7f4127
Notes:
sideshowbarker
2024-07-18 17:48:27 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/598d7f41273 Pull-request: https://github.com/SerenityOS/serenity/pull/7262
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user