mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-28 21:26:22 +00:00
AK: Compute the correct capacity in StringBuilder::try_append_repeated
This was mistakenly broken in 2803d66d87
.
This commit is contained in:
parent
745f288796
commit
a46e9b2adb
Notes:
github-actions[bot]
2025-07-25 16:18:18 +00:00
Author: https://github.com/trflynn89
Commit: a46e9b2adb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5604
Reviewed-by: https://github.com/gmta ✅
1 changed files with 9 additions and 1 deletions
|
@ -179,9 +179,17 @@ ErrorOr<void> StringBuilder::try_append_repeated(StringView string, size_t n)
|
|||
{
|
||||
if (string.is_empty())
|
||||
return {};
|
||||
TRY(will_append(string.length() * (m_mode == Mode::UTF8 ? 1 : 2)));
|
||||
|
||||
if (m_mode == Mode::UTF8) {
|
||||
TRY(will_append(string.length() * n));
|
||||
} else {
|
||||
auto utf16_length = simdutf::utf16_length_from_utf8(string.characters_without_null_termination(), string.length());
|
||||
TRY(will_append(utf16_length * n * 2));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
TRY(try_append(string));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue