mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-22 10:57:18 +00:00
AK: Compare pointers in TypedTransfer<T>::compare()
We can return `true` quickly if the two pointers are identical.
This commit is contained in:
committed by
Tim Flynn
parent
54dd45d3f6
commit
7f8468b0e6
Notes:
github-actions[bot]
2025-07-24 11:20:02 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/7f8468b0e62 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5574 Reviewed-by: https://github.com/trflynn89 ✅
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user