summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-08-17 12:29:24 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-20 16:28:31 +0200
commitb1fc8d2b38cef5510da2506508c4f09a819ccf6f (patch)
tree0c0b78cd7b34ab6c1bb29357f290337f187d469e /AK
parentdf21487794d940bc22e3da9b011a99db43d44693 (diff)
downloadserenity-b1fc8d2b38cef5510da2506508c4f09a819ccf6f.zip
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);
Diffstat (limited to 'AK')
-rw-r--r--AK/Span.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/AK/Span.h b/AK/Span.h
index e6b0d74f61..a0084d6340 100644
--- a/AK/Span.h
+++ b/AK/Span.h
@@ -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)