summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-08-15 18:38:24 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-15 21:21:18 +0200
commitfff581cd725db6b9cc1e1fd25503c68ec2d044d3 (patch)
tree0c0a510f5cbd1c2c6c1613b11209655624eda893 /AK
parent525d51bbb526912946c491e502b57cf439ab3906 (diff)
downloadserenity-fff581cd725db6b9cc1e1fd25503c68ec2d044d3.zip
AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
Diffstat (limited to 'AK')
-rw-r--r--AK/ByteBuffer.h11
-rw-r--r--AK/Vector.h3
2 files changed, 10 insertions, 4 deletions
diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h
index 81da296d94..2c53a578fa 100644
--- a/AK/ByteBuffer.h
+++ b/AK/ByteBuffer.h
@@ -71,8 +71,8 @@ public:
u8* data() { return m_data; }
const u8* data() const { return m_data; }
- Bytes span() { return { data(), size() }; }
- ReadonlyBytes span() const { return { data(), size() }; }
+ Bytes bytes() { return { data(), size() }; }
+ ReadonlyBytes bytes() const { return { data(), size() }; }
u8* offset_pointer(int offset) { return m_data + offset; }
const u8* offset_pointer(int offset) const { return m_data + offset; }
@@ -163,8 +163,8 @@ public:
u8* data() { return m_impl ? m_impl->data() : nullptr; }
const u8* data() const { return m_impl ? m_impl->data() : nullptr; }
- Bytes span() { return m_impl ? m_impl->span() : nullptr; }
- ReadonlyBytes span() const { return m_impl ? m_impl->span() : nullptr; }
+ Bytes bytes() { return m_impl ? m_impl->bytes() : nullptr; }
+ ReadonlyBytes bytes() const { return m_impl ? m_impl->bytes() : nullptr; }
u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
@@ -233,6 +233,9 @@ public:
__builtin_memcpy(this->data() + offset, data, data_size);
}
+ operator Bytes() { return bytes(); }
+ operator ReadonlyBytes() const { return bytes(); }
+
private:
explicit ByteBuffer(RefPtr<ByteBufferImpl>&& impl)
: m_impl(move(impl))
diff --git a/AK/Vector.h b/AK/Vector.h
index 3cf47f160e..aa5b3f5d46 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -243,6 +243,9 @@ public:
return !(*this == other);
}
+ operator Span<T>() { return span(); }
+ operator Span<const T>() const { return span(); }
+
bool contains_slow(const T& value) const
{
for (size_t i = 0; i < size(); ++i) {