mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
AK: Return early in utf8_to_utf16()
for empty strings
No need to validate an empty string.
This commit is contained in:
parent
6f926e6977
commit
408165d2f4
Notes:
github-actions[bot]
2025-06-13 13:10:03 +00:00
Author: https://github.com/gmta
Commit: 408165d2f4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5067
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89
1 changed files with 3 additions and 2 deletions
|
@ -58,11 +58,12 @@ ErrorOr<Utf16ConversionResult> utf8_to_utf16(StringView utf8_view, Endianness en
|
|||
|
||||
ErrorOr<Utf16ConversionResult> utf8_to_utf16(Utf8View const& utf8_view, Endianness endianness)
|
||||
{
|
||||
if (utf8_view.is_empty())
|
||||
return Utf16ConversionResult { Utf16Data {}, 0 };
|
||||
|
||||
// All callers want to allow lonely surrogates, which simdutf does not permit.
|
||||
if (!utf8_view.validate(Utf8View::AllowSurrogates::No)) [[unlikely]]
|
||||
return to_utf16_slow(utf8_view, endianness);
|
||||
if (utf8_view.is_empty())
|
||||
return Utf16ConversionResult { Utf16Data {}, 0 };
|
||||
|
||||
auto const* data = reinterpret_cast<char const*>(utf8_view.bytes());
|
||||
auto length = utf8_view.byte_length();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue