From 78849bbb48120651103fef0882ace6dc38c5c9c8 Mon Sep 17 00:00:00 2001 From: asynts Date: Wed, 12 Aug 2020 11:44:20 +0200 Subject: [PATCH] AK: Add copy_to() and move_to() methods to AK::Span. --- AK/Span.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/AK/Span.h b/AK/Span.h index 4c42c7d63d..ccee6c9ba0 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -154,6 +154,28 @@ public: return this->m_values + start; } + ALWAYS_INLINE void copy_to(Span other) const + { + ASSERT(other.size() >= size()); + __builtin_memcpy(other.data(), data(), sizeof(T) * size()); + } + + ALWAYS_INLINE void copy_trimmed_to(Span other) const + { + __builtin_memcpy(other.data(), data(), sizeof(T) * min(size(), other.size())); + } + + ALWAYS_INLINE void move_to(Span other) const + { + ASSERT(other.size() >= size()); + __builtin_memmove(other.data(), data(), sizeof(T) * size()); + } + + ALWAYS_INLINE void move_trimmed_to(Span other) const + { + __builtin_memmove(other.data(), data(), sizeof(T) * min(size(), other.size())); + } + ALWAYS_INLINE const T& at(size_t index) const { ASSERT(index < this->m_size);