Skip to content

Commit

Permalink
ByteBuffer: Add slice_view(). Works like slice() but makes a wrapper …
Browse files Browse the repository at this point in the history
…only.

So we already have ByteBuffer::wrap() which is like a StringView for random
data. This might not be the best abstraction actually, but this will be
immediately useful so let's add it.
  • Loading branch information
awesomekling committed Jul 27, 2019
1 parent c7a4c8f commit 6f397e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AK/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ class ByteBuffer {
m_impl->trim(size);
}

ByteBuffer slice_view(int offset, int size) const
{
if (is_null())
return {};
if (offset >= this->size())
return {};
if (offset + size >= this->size())
size = this->size() - offset;
return wrap(offset_pointer(offset), size);
}

ByteBuffer slice(int offset, int size) const
{
if (is_null())
Expand Down

0 comments on commit 6f397e2

Please sign in to comment.