Преглед изворни кода

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);
asynts пре 4 година
родитељ
комит
b1fc8d2b38
1 измењених фајлова са 6 додато и 3 уклоњено
  1. 6 3
      AK/Span.h

+ 6 - 3
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)