mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibJS: Avoid StringImpl refcount churn when hashing StringOrSymbol
Add a StringOrSymbol::hash() helper function so we can compute the hash without having to construct a temporary String.
This commit is contained in:
parent
cfd141b4f9
commit
d542049596
1 changed files with 8 additions and 5 deletions
|
@ -135,6 +135,13 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned hash() const
|
||||||
|
{
|
||||||
|
if (is_string())
|
||||||
|
return static_cast<const StringImpl*>(m_ptr)->hash();
|
||||||
|
return ptr_hash(as_symbol());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ALWAYS_INLINE u64 bits() const
|
ALWAYS_INLINE u64 bits() const
|
||||||
{
|
{
|
||||||
|
@ -155,10 +162,6 @@ template<>
|
||||||
struct AK::Traits<JS::StringOrSymbol> : public GenericTraits<JS::StringOrSymbol> {
|
struct AK::Traits<JS::StringOrSymbol> : public GenericTraits<JS::StringOrSymbol> {
|
||||||
static unsigned hash(const JS::StringOrSymbol& key)
|
static unsigned hash(const JS::StringOrSymbol& key)
|
||||||
{
|
{
|
||||||
if (key.is_string())
|
return key.hash();
|
||||||
return key.as_string().hash();
|
|
||||||
if (key.is_symbol())
|
|
||||||
return ptr_hash(key.as_symbol());
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue