From 3d053f244f0cb16be187a8935e8120e221e1c716 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Oct 2020 17:33:58 +0200 Subject: [PATCH] LibJS: Avoid creating a temporary String in StringOrSymbol::operator== --- Libraries/LibJS/Runtime/StringOrSymbol.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h index b8d031affb..6939194183 100644 --- a/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace JS { @@ -118,8 +119,15 @@ public: ALWAYS_INLINE bool operator==(const StringOrSymbol& other) const { - if (is_string()) - return other.is_string() && as_string() == other.as_string(); + if (is_string()) { + if (!other.is_string()) + return false; + auto* this_impl = static_cast(m_ptr); + auto* other_impl = static_cast(other.m_ptr); + if (this_impl->length() != other_impl->length()) + return false; + return !memcmp(this_impl->characters(), other_impl->characters(), this_impl->length()); + } if (is_symbol()) return other.is_symbol() && as_symbol() == other.as_symbol(); return true;