1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-03-29 20:25:34 -04:00 committed by Andreas Kling
parent 8ff36e5910
commit 5c38b14045
3 changed files with 26 additions and 9 deletions

View file

@ -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();
}
}