mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Implement a slightly better FlyString::operator==(String)
This was showing up in Browser profiles, which is silly, so write a new version that doesn't create a temporary String object. There are a whole bunch of these and long-term it would be nice to find a way to share all the very similar logic instead of duplicating it.
This commit is contained in:
@@ -114,16 +114,26 @@ StringView FlyString::view() const
|
||||
return { characters(), length() };
|
||||
}
|
||||
|
||||
bool FlyString::operator==(const String& string) const
|
||||
bool FlyString::operator==(const String& other) const
|
||||
{
|
||||
if (m_impl == string.impl())
|
||||
if (m_impl == other.impl())
|
||||
return true;
|
||||
return String(m_impl.ptr()) == string;
|
||||
|
||||
if (!m_impl)
|
||||
return !other.impl();
|
||||
|
||||
if (!other.impl())
|
||||
return false;
|
||||
|
||||
if (length() != other.length())
|
||||
return false;
|
||||
|
||||
return !__builtin_memcmp(characters(), other.characters(), length());
|
||||
}
|
||||
|
||||
bool FlyString::operator==(const StringView& string) const
|
||||
{
|
||||
return String(string) == String(m_impl.ptr());
|
||||
return *this == String(string);
|
||||
}
|
||||
|
||||
bool FlyString::operator==(const char* string) const
|
||||
|
||||
Reference in New Issue
Block a user