AK: Ensure Utf16FlyString is hash-compatible with Utf16View/Utf16String

This commit is contained in:
Timothy Flynn 2025-08-06 09:09:13 -04:00 committed by Jelle Raaijmakers
parent 274f8ee462
commit 1b611fba67
3 changed files with 25 additions and 0 deletions

View File

@ -165,6 +165,22 @@ struct Formatter<Utf16FlyString> : Formatter<Utf16String> {
}
};
namespace Detail {
template<>
inline constexpr bool IsHashCompatible<Utf16View, Utf16FlyString> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16View> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16String, Utf16FlyString> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16String> = true;
}
}
[[nodiscard]] ALWAYS_INLINE AK::Utf16FlyString operator""_utf16_fly_string(char const* string, size_t length)

View File

@ -8,6 +8,12 @@
#include <AK/Utf16FlyString.h>
static_assert(AK::Concepts::HashCompatible<Utf16String, Utf16FlyString>);
static_assert(AK::Concepts::HashCompatible<Utf16FlyString, Utf16String>);
static_assert(AK::Concepts::HashCompatible<Utf16View, Utf16FlyString>);
static_assert(AK::Concepts::HashCompatible<Utf16FlyString, Utf16View>);
TEST_CASE(empty_string)
{
Utf16FlyString fly {};

View File

@ -14,6 +14,9 @@
#include <AK/Utf16String.h>
#include <AK/Utf32View.h>
static_assert(AK::Concepts::HashCompatible<Utf16String, Utf16View>);
static_assert(AK::Concepts::HashCompatible<Utf16View, Utf16String>);
static Utf16String make_copy(Utf16String const& string)
{
return string.has_ascii_storage()