From cc765e14caf24e5a4c28c22aa76fd607e529a0b8 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 5 Oct 2020 11:15:49 -0400 Subject: [PATCH] AK: Move StringImpl::operator== implementation into StringImpl --- AK/String.cpp | 5 +---- AK/StringImpl.h | 7 +++++++ Libraries/LibJS/Runtime/StringOrSymbol.h | 5 +---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index feb482a714d..19309e0f4be 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -60,10 +60,7 @@ bool String::operator==(const String& other) const if (!other.m_impl) return false; - if (length() != other.length()) - return false; - - return !memcmp(characters(), other.characters(), length()); + return *m_impl == *other.m_impl; } bool String::operator==(const StringView& other) const diff --git a/AK/StringImpl.h b/AK/StringImpl.h index e85798a06c2..1b9360c8f03 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -70,6 +70,13 @@ public: return characters()[i]; } + bool operator==(const StringImpl& other) const + { + if (length() != other.length()) + return false; + return !__builtin_memcmp(characters(), other.characters(), length()); + } + unsigned hash() const { if (!m_has_hash) diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h index bb4aba3e7a0..e647b50b0f1 100644 --- a/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -30,7 +30,6 @@ #include #include #include -#include namespace JS { @@ -132,9 +131,7 @@ public: 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()); + return *this_impl == *other_impl; } if (is_symbol()) return other.is_symbol() && as_symbol() == other.as_symbol();