mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add a fallible StringBuilder::create() factory function
This is nice, and is also used by the Jakt runtime.
This commit is contained in:
parent
21c2d8bd98
commit
543890c5c9
Notes:
sideshowbarker
2024-07-17 03:26:24 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/543890c5c9 Pull-request: https://github.com/SerenityOS/serenity/pull/16396 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅
2 changed files with 9 additions and 0 deletions
|
@ -36,6 +36,13 @@ inline ErrorOr<void> StringBuilder::will_append(size_t size)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<StringBuilder> StringBuilder::create(size_t initial_capacity)
|
||||
{
|
||||
StringBuilder builder;
|
||||
TRY(builder.m_buffer.try_ensure_capacity(initial_capacity));
|
||||
return builder;
|
||||
}
|
||||
|
||||
StringBuilder::StringBuilder(size_t initial_capacity)
|
||||
{
|
||||
m_buffer.ensure_capacity(initial_capacity);
|
||||
|
|
|
@ -18,6 +18,8 @@ class StringBuilder {
|
|||
public:
|
||||
using OutputType = DeprecatedString;
|
||||
|
||||
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
|
||||
|
||||
explicit StringBuilder(size_t initial_capacity = inline_capacity);
|
||||
~StringBuilder() = default;
|
||||
|
||||
|
|
Loading…
Reference in a new issue