From 5c38b140453ab13defb1e0d03b046c58acdd6228 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 29 Mar 2023 20:25:34 -0400 Subject: AK: Remove arbitrary 1 KB limit when filling a BufferedStream's buffer When reading, we currently only fill a BufferedStream's buffer when it is empty, and only with 1 KB of data. This means that while the buffer defaults to a size of 16 KB, at least 15 KB is always unused. --- AK/CircularBuffer.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'AK/CircularBuffer.cpp') diff --git a/AK/CircularBuffer.cpp b/AK/CircularBuffer.cpp index 0c6363c9fe..6ffe7ede66 100644 --- a/AK/CircularBuffer.cpp +++ b/AK/CircularBuffer.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace AK { @@ -189,4 +190,20 @@ ErrorOr CircularBuffer::discard(size_t discarding_size) return {}; } +ErrorOr CircularBuffer::fill_from_stream(Stream& stream) +{ + auto next_span = next_write_span(); + if (next_span.size() == 0) + return 0; + + auto bytes = TRY(stream.read_some(next_span)); + m_used_space += bytes.size(); + + m_seekback_limit += bytes.size(); + if (m_seekback_limit > capacity()) + m_seekback_limit = capacity(); + + return bytes.size(); +} + } -- cgit v1.2.3