diff options
author | asynts <asynts@gmail.com> | 2020-08-17 12:29:24 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-20 16:28:31 +0200 |
commit | b1fc8d2b38cef5510da2506508c4f09a819ccf6f (patch) | |
tree | 0c0b78cd7b34ab6c1bb29357f290337f187d469e /AK/Span.h | |
parent | df21487794d940bc22e3da9b011a99db43d44693 (diff) | |
download | serenity-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/Span.h')
-rw-r--r-- | AK/Span.h | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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) |