AK: Cache hashes for fly string interning

HashTable only stores per-bucket hash when traits say equality is slow.
The FlyString/Utf16FlyString interning tables compare full string data,
so equality is not cheap. Mark these traits as slow-equality so hashes
are stored and checked first, reducing probe cost in hot interning
lookups.
This commit is contained in:
Andreas Kling 2026-01-26 17:54:48 +01:00 committed by Andreas Kling
parent 81bee185e6
commit 048a0ab32b
2 changed files with 2 additions and 0 deletions

View file

@ -17,6 +17,7 @@ namespace AK {
struct FlyStringTableHashTraits : public Traits<Detail::StringData const*> {
static u32 hash(Detail::StringData const* string) { return string->hash(); }
static bool equals(Detail::StringData const* a, Detail::StringData const* b) { return *a == *b; }
static constexpr bool may_have_slow_equality_check() { return true; }
};
static auto& all_fly_strings()

View file

@ -13,6 +13,7 @@ namespace AK {
struct Utf16FlyStringTableHashTraits : public Traits<Detail::Utf16StringData const*> {
static u32 hash(Detail::Utf16StringData const* string) { return string->hash(); }
static bool equals(Detail::Utf16StringData const* a, Detail::Utf16StringData const* b) { return *a == *b; }
static constexpr bool may_have_slow_equality_check() { return true; }
};
static auto& all_utf16_fly_strings()