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:
parent
df21487794
commit
b1fc8d2b38
Notes:
sideshowbarker
2024-07-19 03:24:31 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/b1fc8d2b38c Pull-request: https://github.com/SerenityOS/serenity/pull/3220 Reviewed-by: https://github.com/awesomekling
1 changed files with 6 additions and 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)
|
||||
|
|
Loading…
Add table
Reference in a new issue