mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
AK: Move StringImpl::operator== implementation into StringImpl
This commit is contained in:
parent
ee9c18c118
commit
cc765e14ca
|
@ -60,10 +60,7 @@ bool String::operator==(const String& other) const
|
||||||
if (!other.m_impl)
|
if (!other.m_impl)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (length() != other.length())
|
return *m_impl == *other.m_impl;
|
||||||
return false;
|
|
||||||
|
|
||||||
return !memcmp(characters(), other.characters(), length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::operator==(const StringView& other) const
|
bool String::operator==(const StringView& other) const
|
||||||
|
|
|
@ -70,6 +70,13 @@ public:
|
||||||
return characters()[i];
|
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
|
unsigned hash() const
|
||||||
{
|
{
|
||||||
if (!m_has_hash)
|
if (!m_has_hash)
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <LibJS/Runtime/PrimitiveString.h>
|
#include <LibJS/Runtime/PrimitiveString.h>
|
||||||
#include <LibJS/Runtime/Symbol.h>
|
#include <LibJS/Runtime/Symbol.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
|
@ -132,9 +131,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
auto* this_impl = static_cast<const StringImpl*>(m_ptr);
|
auto* this_impl = static_cast<const StringImpl*>(m_ptr);
|
||||||
auto* other_impl = static_cast<const StringImpl*>(other.m_ptr);
|
auto* other_impl = static_cast<const StringImpl*>(other.m_ptr);
|
||||||
if (this_impl->length() != other_impl->length())
|
return *this_impl == *other_impl;
|
||||||
return false;
|
|
||||||
return !memcmp(this_impl->characters(), other_impl->characters(), this_impl->length());
|
|
||||||
}
|
}
|
||||||
if (is_symbol())
|
if (is_symbol())
|
||||||
return other.is_symbol() && as_symbol() == other.as_symbol();
|
return other.is_symbol() && as_symbol() == other.as_symbol();
|
||||||
|
|
Loading…
Reference in a new issue