1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

AK+Userland: Introduce ByteString::create_and_overwrite

And replace two users of raw StringImpl with it.
This commit is contained in:
Dan Klishch 2024-01-22 13:26:55 -05:00 committed by Andrew Kaster
parent f7c952f842
commit 061f902f95
3 changed files with 28 additions and 12 deletions

View file

@ -39,13 +39,10 @@ ErrorOr<ByteString> decode(Decoder& decoder)
if (length == 0)
return ByteString::empty();
char* text_buffer = nullptr;
auto text_impl = StringImpl::create_uninitialized(length, text_buffer);
Bytes bytes { text_buffer, length };
TRY(decoder.decode_into(bytes));
return ByteString { *text_impl };
return ByteString::create_and_overwrite(length, [&](Bytes bytes) -> ErrorOr<void> {
TRY(decoder.decode_into(bytes));
return {};
});
}
template<>