mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +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:
parent
6242e029ed
commit
35329400b8
1 changed files with 14 additions and 4 deletions
|
@ -114,16 +114,26 @@ StringView FlyString::view() const
|
||||||
return { characters(), length() };
|
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 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
|
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
|
bool FlyString::operator==(const char* string) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue