mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
AK: Let FlyString::hash() assume that the string was already hashed
Since the FlyString deduplication mechanism uses a HashTable, we know that any StringImpl inside a non-null FlyString will already have its lazily computed hash.
This commit is contained in:
parent
d1ffdea550
commit
02e0fab19a
2 changed files with 7 additions and 2 deletions
|
@ -55,7 +55,7 @@ public:
|
||||||
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
|
const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
|
||||||
size_t length() const { return m_impl ? m_impl->length() : 0; }
|
size_t length() const { return m_impl ? m_impl->length() : 0; }
|
||||||
|
|
||||||
u32 hash() const { return m_impl ? m_impl->hash() : 0; }
|
[[gnu::always_inline]] inline u32 hash() const { return m_impl ? m_impl->existing_hash() : 0; }
|
||||||
|
|
||||||
StringView view() const;
|
StringView view() const;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ private:
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Traits<FlyString> : public GenericTraits<FlyString> {
|
struct Traits<FlyString> : public GenericTraits<FlyString> {
|
||||||
static unsigned hash(const FlyString& s) { return s.impl() ? s.impl()->hash() : 0; }
|
static unsigned hash(const FlyString& s) { return s.hash(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,11 @@ public:
|
||||||
return m_hash;
|
return m_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned existing_hash() const
|
||||||
|
{
|
||||||
|
return m_hash;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_fly() const { return m_fly; }
|
bool is_fly() const { return m_fly; }
|
||||||
void set_fly(Badge<FlyString>, bool fly) const { m_fly = fly; }
|
void set_fly(Badge<FlyString>, bool fly) const { m_fly = fly; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue