summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-09-15 12:18:31 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-15 20:36:45 +0200
commitc8ed882b8ec4501c64ccbd74f5c215710c66371e (patch)
treeab44aaf512e8f169922a79d5a433944090d9c859 /AK
parent83d0803861ddb77c07645a678f90d6808a1c5cd3 (diff)
downloadserenity-c8ed882b8ec4501c64ccbd74f5c215710c66371e.zip
AK: Add OutputMemoryStream::fill_to_end.
Diffstat (limited to 'AK')
-rw-r--r--AK/MemoryStream.h7
-rw-r--r--AK/Span.h7
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() }; }
diff --git a/AK/Span.h b/AK/Span.h
index f4512a0c15..0852cf9b31 100644
--- a/AK/Span.h
+++ b/AK/Span.h
@@ -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