AK+LibJS+LibWeb: Recognize that our UTF-16 string is actually WTF-16

For the web, we allow a wobbly UTF-16 encoding (i.e. lonely surrogates
are permitted). Only in a few exceptional cases do we strictly require
valid UTF-16. As such, our `validate(AllowLonelySurrogates::Yes)` calls
will always succeed. It's a wasted effort to ever make such a check.

This patch eliminates such invocations. The validation methods will now
only check for strict UTF-16, and are only invoked when needed.
This commit is contained in:
Timothy Flynn
2025-08-08 16:32:26 -04:00
committed by Tim Flynn
parent 36c7302178
commit 8472e469f4
Notes: github-actions[bot] 2025-08-13 13:57:41 +00:00
20 changed files with 61 additions and 158 deletions

View File

@@ -27,7 +27,6 @@ public:
static Utf16FlyString from_utf8_but_should_be_ported_to_utf16(StringView string) { return from_utf8_without_validation(string); }
static Utf16FlyString from_utf16(Utf16View const&);
static Utf16FlyString from_utf16_without_validation(Utf16View const&);
template<typename T>
requires(IsOneOf<RemoveCVReference<T>, Utf16String, Utf16FlyString>)
@@ -193,8 +192,5 @@ inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16String> = true;
[[nodiscard]] ALWAYS_INLINE AK::Utf16FlyString operator""_utf16_fly_string(char16_t const* string, size_t length)
{
AK::Utf16View view { string, length };
ASSERT(view.validate());
return AK::Utf16FlyString::from_utf16_without_validation(view);
return AK::Utf16FlyString::from_utf16({ string, length });
}