mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
AK: Avoid temporary Vector<u8> when encoding Base64
Instead, decode directly into an uninitialized StringData object. This avoids the redundant vector allocation + memory copy.
This commit is contained in:
parent
2453f0bc04
commit
c9c98a150d
Notes:
github-actions[bot]
2025-11-29 14:41:19 +00:00
Author: https://github.com/awesomekling
Commit: c9c98a150d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6975
Reviewed-by: https://github.com/trflynn89
2 changed files with 10 additions and 6 deletions
|
|
@ -83,16 +83,20 @@ static ErrorOr<ByteBuffer> decode_base64_impl(StringView input, LastChunkHandlin
|
|||
|
||||
static ErrorOr<String> encode_base64_impl(StringView input, simdutf::base64_options options)
|
||||
{
|
||||
Vector<u8> output;
|
||||
TRY(output.try_resize(simdutf::base64_length_from_binary(input.length(), options)));
|
||||
if (input.is_empty())
|
||||
return String {};
|
||||
|
||||
u8* buffer = nullptr;
|
||||
auto output = TRY(AK::Detail::StringData::create_uninitialized(
|
||||
simdutf::base64_length_from_binary(input.length(), options), buffer));
|
||||
|
||||
simdutf::binary_to_base64(
|
||||
input.characters_without_null_termination(),
|
||||
input.length(),
|
||||
reinterpret_cast<char*>(output.data()),
|
||||
reinterpret_cast<char*>(buffer),
|
||||
options);
|
||||
|
||||
return String::from_utf8_without_validation(output);
|
||||
return String { move(output) };
|
||||
}
|
||||
|
||||
ErrorOr<ByteBuffer> decode_base64(StringView input, LastChunkHandling last_chunk_handling)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ public:
|
|||
other.m_impl = { .short_string = ShortString::create_empty() };
|
||||
}
|
||||
|
||||
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
||||
|
||||
StringBase& operator=(StringBase&&);
|
||||
StringBase& operator=(StringBase const&);
|
||||
|
||||
|
|
@ -123,8 +125,6 @@ private:
|
|||
friend class ::AK::FlyString;
|
||||
friend struct ::AK::Detail::ShortString;
|
||||
|
||||
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
|
||||
|
||||
explicit constexpr StringBase(nullptr_t)
|
||||
: m_impl { .data = nullptr }
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue