mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 14:57:54 +03: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:
parent
e6fc7b3ff7
commit
d517e7fb3a
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d517e7fb3a
@ -97,7 +97,7 @@ bool FlyString::is_empty() const
|
||||
|
||||
unsigned FlyString::hash() const
|
||||
{
|
||||
return bytes_as_string_view().hash();
|
||||
return String::fly_string_data_to_hash({}, m_data);
|
||||
}
|
||||
|
||||
FlyString::operator String() const
|
||||
@ -170,7 +170,7 @@ DeprecatedFlyString FlyString::to_deprecated_fly_string() const
|
||||
|
||||
unsigned Traits<FlyString>::hash(FlyString const& fly_string)
|
||||
{
|
||||
return fly_string.bytes_as_string_view().hash();
|
||||
return fly_string.hash();
|
||||
}
|
||||
|
||||
ErrorOr<void> Formatter<FlyString>::format(FormatBuilder& builder, FlyString const& fly_string)
|
||||
|
@ -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);
|
||||
|
@ -213,6 +213,7 @@ public:
|
||||
|
||||
[[nodiscard]] static String fly_string_data_to_string(Badge<FlyString>, uintptr_t const&);
|
||||
[[nodiscard]] static StringView fly_string_data_to_string_view(Badge<FlyString>, uintptr_t const&);
|
||||
[[nodiscard]] static u32 fly_string_data_to_hash(Badge<FlyString>, uintptr_t const&);
|
||||
[[nodiscard]] uintptr_t to_fly_string_data(Badge<FlyString>) const;
|
||||
|
||||
static void ref_fly_string_data(Badge<FlyString>, uintptr_t);
|
||||
|
Loading…
Reference in New Issue
Block a user