mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
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.
This commit is contained in:
parent
525d51bbb5
commit
fff581cd72
18 changed files with 51 additions and 45 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue