mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +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
Notes:
sideshowbarker
2024-07-19 02:03:46 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d5420495964
1 changed files with 8 additions and 5 deletions
|
@ -135,6 +135,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
unsigned hash() const
|
||||
{
|
||||
if (is_string())
|
||||
return static_cast<const StringImpl*>(m_ptr)->hash();
|
||||
return ptr_hash(as_symbol());
|
||||
}
|
||||
|
||||
private:
|
||||
ALWAYS_INLINE u64 bits() const
|
||||
{
|
||||
|
@ -155,10 +162,6 @@ template<>
|
|||
struct AK::Traits<JS::StringOrSymbol> : public GenericTraits<JS::StringOrSymbol> {
|
||||
static unsigned hash(const JS::StringOrSymbol& key)
|
||||
{
|
||||
if (key.is_string())
|
||||
return key.as_string().hash();
|
||||
if (key.is_symbol())
|
||||
return ptr_hash(key.as_symbol());
|
||||
return 0;
|
||||
return key.hash();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue