AK: Add AllocatingMemoryStream::peek_some_contiguous()

Expose the next contiguous range of readable bytes at the current read
offset without copying. This lets callers hand the underlying chunk
straight to write/send without round-tripping through a user-space
buffer, which is important when the stream is used as a back-pressure
queue and the total queued size can grow to many megabytes.
This commit is contained in:
Andreas Kling
2026-04-21 21:13:41 +02:00
committed by Jelle Raaijmakers
parent 25254d5a20
commit 612c61cc16
Notes: github-actions[bot] 2026-04-22 11:33:35 +00:00
2 changed files with 11 additions and 5 deletions

View File

@@ -91,6 +91,7 @@ public:
static constexpr size_t CHUNK_SIZE = 4096;
void peek_some(Bytes) const;
ReadonlyBytes peek_some_contiguous() const;
virtual ErrorOr<Bytes> read_some(Bytes) override;
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
@@ -107,7 +108,7 @@ private:
// Note: We set the inline buffer capacity to zero to make moving chunks as efficient as possible.
using Chunk = AK::Detail::ByteBuffer<0>;
ErrorOr<ReadonlyBytes> next_read_range(size_t read_offset) const;
ReadonlyBytes next_read_range(size_t read_offset) const;
ErrorOr<Bytes> next_write_range();
void cleanup_unused_chunks();