mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
AK: Add String::operator==(StringView)
Comparing a String to a StringView would instantiate a temporary String just for the comparison. Let's not do that. :^)
This commit is contained in:
parent
b020a5e7ce
commit
cd8278e489
2 changed files with 17 additions and 0 deletions
|
@ -19,6 +19,20 @@ bool String::operator==(const String& other) const
|
|||
return !memcmp(characters(), other.characters(), length());
|
||||
}
|
||||
|
||||
bool String::operator==(const StringView& other) const
|
||||
{
|
||||
if (!m_impl)
|
||||
return !other.m_characters;
|
||||
|
||||
if (!other.m_characters)
|
||||
return false;
|
||||
|
||||
if (length() != other.length())
|
||||
return false;
|
||||
|
||||
return !memcmp(characters(), other.characters_without_null_termination(), length());
|
||||
}
|
||||
|
||||
bool String::operator<(const String& other) const
|
||||
{
|
||||
if (!m_impl)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue