From b1fc8d2b38cef5510da2506508c4f09a819ccf6f Mon Sep 17 00:00:00 2001 From: asynts Date: Mon, 17 Aug 2020 12:29:24 +0200 Subject: [PATCH] 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::Type> because the following would not work: ReadonlyBytes bytes0; Bytes bytes1; // Won't work because this calls Span::copy_to(Span) // but the method was defined as Span::copy_to(Span) bytes0.copy_to(bytes1); --- AK/Span.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AK/Span.h b/AK/Span.h index e6b0d74f616..a0084d63403 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::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::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)