AK: Add OutputMemoryStream::fill_to_end.

This commit is contained in:
asynts 2020-09-15 12:18:31 +02:00 committed by Andreas Kling
parent 83d0803861
commit c8ed882b8e
Notes: sideshowbarker 2024-07-19 02:38:22 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -186,6 +186,13 @@ public:
return true; return true;
} }
size_t fill_to_end(u8 value)
{
const auto nwritten = m_bytes.slice(m_offset).fill(value);
m_offset += nwritten;
return nwritten;
}
ReadonlyBytes bytes() const { return { data(), size() }; } ReadonlyBytes bytes() const { return { data(), size() }; }
Bytes bytes() { return { data(), size() }; } Bytes bytes() { return { data(), size() }; }

View file

@ -165,11 +165,12 @@ public:
return TypedTransfer<typename RemoveConst<T>::Type>::copy(other.data(), data(), count); return TypedTransfer<typename RemoveConst<T>::Type>::copy(other.data(), data(), count);
} }
ALWAYS_INLINE void fill(const T& value) ALWAYS_INLINE size_t fill(const T& value)
{ {
for (size_t idx = 0; idx < size(); ++idx) { for (size_t idx = 0; idx < size(); ++idx)
data()[idx] = value; data()[idx] = value;
}
return size();
} }
bool contains_slow(const T& value) const bool contains_slow(const T& value) const