mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Allow passing an offset to CircularBuffer::next_read_span()
This commit is contained in:
parent
046a9faeb3
commit
d12036132e
Notes:
sideshowbarker
2024-07-17 01:00:06 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/d12036132e Pull-request: https://github.com/SerenityOS/serenity/pull/19332 Reviewed-by: https://github.com/linusg ✅
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
|
||||
|
|
|
@ -50,7 +50,7 @@ protected:
|
|||
[[nodiscard]] bool is_wrapping_around() const;
|
||||
|
||||
[[nodiscard]] Bytes next_write_span();
|
||||
[[nodiscard]] ReadonlyBytes next_read_span() const;
|
||||
[[nodiscard]] ReadonlyBytes next_read_span(size_t offset = 0) const;
|
||||
[[nodiscard]] ReadonlyBytes next_read_span_with_seekback(size_t distance) const;
|
||||
|
||||
ByteBuffer m_buffer {};
|
||||
|
|
Loading…
Reference in a new issue