mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
AK: Allow passing an offset to CircularBuffer::next_read_span()
This commit is contained in:
parent
046a9faeb3
commit
d12036132e
2 changed files with 14 additions and 3 deletions
|
@ -97,9 +97,20 @@ Bytes CircularBuffer::next_write_span()
|
|||
return m_buffer.span().slice(m_reading_head + m_used_space, capacity() - (m_reading_head + m_used_space));
|
||||
}
|
||||
|
||||
ReadonlyBytes CircularBuffer::next_read_span() const
|
||||
ReadonlyBytes CircularBuffer::next_read_span(size_t offset) const
|
||||
{
|
||||
return m_buffer.span().slice(m_reading_head, min(capacity() - m_reading_head, m_used_space));
|
||||
auto reading_head = m_reading_head;
|
||||
auto used_space = m_used_space;
|
||||
|
||||
if (offset > 0) {
|
||||
if (offset >= used_space)
|
||||
return Bytes {};
|
||||
|
||||
reading_head = (reading_head + offset) % capacity();
|
||||
used_space -= offset;
|
||||
}
|
||||
|
||||
return m_buffer.span().slice(reading_head, min(capacity() - reading_head, used_space));
|
||||
}
|
||||
|
||||
ReadonlyBytes CircularBuffer::next_read_span_with_seekback(size_t distance) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue