mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 01:56:38 +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:
parent
54dd45d3f6
commit
7f8468b0e6
Notes:
github-actions[bot]
2025-07-24 11:20:02 +00:00
Author: https://github.com/gmta
Commit: 7f8468b0e6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5574
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 3 additions and 10 deletions
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
static bool compare(T const* a, T const* b, size_t count)
|
static bool compare(T const* a, T const* b, size_t count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0 || a == b)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if constexpr (Traits<T>::is_trivial())
|
if constexpr (Traits<T>::is_trivial())
|
||||||
|
|
|
@ -463,17 +463,10 @@ public:
|
||||||
if (needle.length_in_code_units() > length_in_code_units())
|
if (needle.length_in_code_units() > length_in_code_units())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (has_ascii_storage() && needle.has_ascii_storage()) {
|
if (has_ascii_storage() && needle.has_ascii_storage())
|
||||||
if (m_string.ascii == needle.m_string.ascii)
|
|
||||||
return true;
|
|
||||||
return ascii_span().starts_with(needle.ascii_span());
|
return ascii_span().starts_with(needle.ascii_span());
|
||||||
}
|
if (!has_ascii_storage() && !needle.has_ascii_storage())
|
||||||
|
|
||||||
if (!has_ascii_storage() && !needle.has_ascii_storage()) {
|
|
||||||
if (m_string.utf16 == needle.m_string.utf16)
|
|
||||||
return true;
|
|
||||||
return utf16_span().starts_with(needle.utf16_span());
|
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) {
|
for (auto this_it = begin(), needle_it = needle.begin(); needle_it != needle.end(); ++needle_it, ++this_it) {
|
||||||
if (*this_it != *needle_it)
|
if (*this_it != *needle_it)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue