mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-04 15:19:42 +00:00
AK: Optimize StringView::operator==(const char*) a little bit
Don't compute the strlen() of the string we're comparing against first. This can save a lot of time if we're comparing against something that already fails to match in the first few characters.
This commit is contained in:
parent
87bb00f6ab
commit
31ac93d051
Notes:
sideshowbarker
2024-07-18 21:59:26 +09:00
Author: https://github.com/awesomekling
Commit: 31ac93d051
1 changed files with 8 additions and 4 deletions
|
@ -144,11 +144,15 @@ public:
|
||||||
return !cstring;
|
return !cstring;
|
||||||
if (!cstring)
|
if (!cstring)
|
||||||
return false;
|
return false;
|
||||||
size_t other_length = __builtin_strlen(cstring);
|
// NOTE: `m_characters` is not guaranteed to be null-terminated, but `cstring` is.
|
||||||
if (m_length != other_length)
|
const char* cp = cstring;
|
||||||
return false;
|
for (size_t i = 0; i < m_length; ++i) {
|
||||||
return !__builtin_memcmp(m_characters, cstring, m_length);
|
if (m_characters[i] != *(cp++))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !*cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const char* cstring) const
|
bool operator!=(const char* cstring) const
|
||||||
{
|
{
|
||||||
return !(*this == cstring);
|
return !(*this == cstring);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue