AK: Compare pointers in TypedTransfer<T>::compare()

We can return `true` quickly if the two pointers are identical.
This commit is contained in:
Jelle Raaijmakers 2025-07-23 20:21:42 +02:00 committed by Tim Flynn
commit 7f8468b0e6
Notes: github-actions[bot] 2025-07-24 11:20:02 +00:00
2 changed files with 3 additions and 10 deletions

View file

@ -56,7 +56,7 @@ public:
static bool compare(T const* a, T const* b, size_t count)
{
if (count == 0)
if (count == 0 || a == b)
return true;
if constexpr (Traits<T>::is_trivial())

View file

@ -463,17 +463,10 @@ public:
if (needle.length_in_code_units() > length_in_code_units())
return false;
if (has_ascii_storage() && needle.has_ascii_storage()) {
if (m_string.ascii == needle.m_string.ascii)
return true;
if (has_ascii_storage() && needle.has_ascii_storage())
return ascii_span().starts_with(needle.ascii_span());
}
if (!has_ascii_storage() && !needle.has_ascii_storage()) {
if (m_string.utf16 == needle.m_string.utf16)
return true;
if (!has_ascii_storage() && !needle.has_ascii_storage())
return utf16_span().starts_with(needle.utf16_span());
}
for (auto this_it = begin(), needle_it = needle.begin(); needle_it != needle.end(); ++needle_it, ++this_it) {
if (*this_it != *needle_it)