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

AK: Use TypedTransfer in Span::copy_to.

This commit is contained in:
asynts 2020-09-09 13:44:51 +02:00 committed by Andreas Kling
parent 910924f559
commit a7f786fc0a

View file

@ -27,8 +27,8 @@
#pragma once #pragma once
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Checked.h>
#include <AK/Iterator.h> #include <AK/Iterator.h>
#include <AK/TypedTransfer.h>
#include <AK/Types.h> #include <AK/Types.h>
namespace AK { namespace AK {
@ -156,15 +156,13 @@ public:
ALWAYS_INLINE size_t copy_to(Span<typename RemoveConst<T>::Type> other) const ALWAYS_INLINE size_t copy_to(Span<typename RemoveConst<T>::Type> other) const
{ {
ASSERT(other.size() >= size()); ASSERT(other.size() >= size());
__builtin_memmove(other.data(), data(), sizeof(T) * size()); return TypedTransfer<typename RemoveConst<T>::Type>::copy(other.data(), data(), size());
return size();
} }
ALWAYS_INLINE size_t copy_trimmed_to(Span<typename RemoveConst<T>::Type> other) const ALWAYS_INLINE size_t copy_trimmed_to(Span<typename RemoveConst<T>::Type> other) const
{ {
auto count = min(size(), other.size()); const auto count = min(size(), other.size());
__builtin_memmove(other.data(), data(), sizeof(T) * count); return TypedTransfer<typename RemoveConst<T>::Type>::copy(other.data(), data(), count);
return count;
} }
ALWAYS_INLINE void fill(const T& value) ALWAYS_INLINE void fill(const T& value)
@ -210,6 +208,14 @@ public:
return *this; return *this;
} }
bool operator==(Span<T> other) const
{
if (size() != other.size())
return false;
return TypedTransfer<T>::compare(data(), other.data(), size());
}
ALWAYS_INLINE operator Span<const T>() const ALWAYS_INLINE operator Span<const T>() const
{ {
return { data(), size() }; return { data(), size() };