1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

AK: Make FlyString::hash() use the cached hash in StringData if possible

This avoids rehashing the string every time.
This commit is contained in:
Andreas Kling 2023-03-08 23:11:59 +01:00
parent e6fc7b3ff7
commit d517e7fb3a
3 changed files with 15 additions and 2 deletions

View file

@ -565,6 +565,18 @@ StringView String::fly_string_data_to_string_view(Badge<FlyString>, uintptr_t co
return string_data->bytes_as_string_view();
}
u32 String::fly_string_data_to_hash(Badge<FlyString>, uintptr_t const& data)
{
if (has_short_string_bit(data)) {
auto const* short_string = reinterpret_cast<ShortString const*>(&data);
auto bytes = short_string->bytes();
return string_hash(reinterpret_cast<char const*>(bytes.data()), bytes.size());
}
auto const* string_data = reinterpret_cast<Detail::StringData const*>(data);
return string_data->hash();
}
uintptr_t String::to_fly_string_data(Badge<FlyString>) const
{
return reinterpret_cast<uintptr_t>(m_data);