AK: Span: Fix signature of copy_to() and copy_trimmed_to().

Two changes were made

 1. copy_to() and copy_trimmed_to() now return how many bytes were
    copied.

 2. The argument was changed to Span<typename RemoveConst<T>::Type>
    because the following would not work:

        ReadonlyBytes bytes0;
        Bytes bytes1;

        // Won't work because this calls Span<const u8>::copy_to(Span<u8>)
        // but the method was defined as Span<const u8>::copy_to(Span<const u8>)
        bytes0.copy_to(bytes1);
This commit is contained in:
asynts 2020-08-17 12:29:24 +02:00 committed by Andreas Kling
parent df21487794
commit b1fc8d2b38
Notes: sideshowbarker 2024-07-19 03:24:31 +09:00

View file

@ -164,15 +164,18 @@ public:
return this->m_values + start;
}
ALWAYS_INLINE void copy_to(Span other) const
ALWAYS_INLINE size_t copy_to(Span<typename RemoveConst<T>::Type> other) const
{
ASSERT(other.size() >= size());
__builtin_memmove(other.data(), data(), sizeof(T) * size());
return size();
}
ALWAYS_INLINE void copy_trimmed_to(Span other) const
ALWAYS_INLINE size_t copy_trimmed_to(Span<typename RemoveConst<T>::Type> other) const
{
__builtin_memmove(other.data(), data(), sizeof(T) * min(size(), other.size()));
auto count = min(size(), other.size());
__builtin_memmove(other.data(), data(), sizeof(T) * count);
return count;
}
ALWAYS_INLINE void fill(const T& value)