diff options
author | asynts <asynts@gmail.com> | 2020-09-15 12:18:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-15 20:36:45 +0200 |
commit | c8ed882b8ec4501c64ccbd74f5c215710c66371e (patch) | |
tree | ab44aaf512e8f169922a79d5a433944090d9c859 /AK | |
parent | 83d0803861ddb77c07645a678f90d6808a1c5cd3 (diff) | |
download | serenity-c8ed882b8ec4501c64ccbd74f5c215710c66371e.zip |
AK: Add OutputMemoryStream::fill_to_end.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/MemoryStream.h | 7 | ||||
-rw-r--r-- | AK/Span.h | 7 |
2 files changed, 11 insertions, 3 deletions
diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index 103a72b8f1..95080f1247 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -186,6 +186,13 @@ public: 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() }; } Bytes bytes() { return { data(), size() }; } @@ -165,11 +165,12 @@ public: 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; - } + + return size(); } bool contains_slow(const T& value) const |