1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

Vector: Use memcmp for comparing two vectors with trivial elements

This commit is contained in:
Andreas Kling 2019-08-07 15:05:10 +02:00
parent 6d97caf124
commit e8e85f5457
3 changed files with 39 additions and 8 deletions

View file

@ -85,6 +85,18 @@ public:
for (size_t i = 0; i < count; ++i)
new (&destination[i]) T(source[i]);
}
static bool compare(const T* a, const T* b, size_t count)
{
if constexpr (Traits<T>::is_trivial())
return !memcmp(a, b, count * sizeof(T));
for (size_t i = 0; i < count; ++i) {
if (a[i] != b[i])
return false;
}
return true;
}
};
template<typename T, int inline_capacity = 0>
@ -178,13 +190,7 @@ public:
{
if (m_size != other.m_size)
return false;
for (int i = 0; i < m_size; ++i) {
if (at(i) != other.at(i))
return false;
}
return true;
return TypedTransfer<T>::compare(data(), other.data(), size());
}
bool operator!=(const Vector& other) const