summaryrefslogtreecommitdiff
path: root/AK/CircularBuffer.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-03-29 20:25:34 -0400
committerAndreas Kling <kling@serenityos.org>2023-03-30 08:47:22 +0200
commit5c38b140453ab13defb1e0d03b046c58acdd6228 (patch)
tree7b5af6d5538d53e108150459b41d691dde4e6635 /AK/CircularBuffer.cpp
parent8ff36e5910445ad59ceb5d1d2acb84381c15036e (diff)
downloadserenity-5c38b140453ab13defb1e0d03b046c58acdd6228.zip
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.
Diffstat (limited to 'AK/CircularBuffer.cpp')
-rw-r--r--AK/CircularBuffer.cpp17
1 files changed, 17 insertions, 0 deletions
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 <AK/CircularBuffer.h>
#include <AK/MemMem.h>
+#include <AK/Stream.h>
namespace AK {
@@ -189,4 +190,20 @@ ErrorOr<void> CircularBuffer::discard(size_t discarding_size)
return {};
}
+ErrorOr<size_t> 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();
+}
+
}