1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:57:36 +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

@ -231,12 +231,11 @@ private:
if (m_buffer.empty_space() == 0)
return 0;
// TODO: Figure out if we can do direct writes in a comfortable way.
Array<u8, 1024> temporary_buffer;
auto const fillable_slice = temporary_buffer.span().trim(min(temporary_buffer.size(), m_buffer.empty_space()));
size_t nread = 0;
do {
auto result = stream().read_some(fillable_slice);
while (true) {
auto result = m_buffer.fill_from_stream(stream());
if (result.is_error()) {
if (!result.error().is_errno())
return result.release_error();
@ -246,11 +245,11 @@ private:
break;
return result.release_error();
}
auto const filled_slice = result.value();
VERIFY(m_buffer.write(filled_slice) == filled_slice.size());
nread += filled_slice.size();
nread += result.value();
break;
} while (true);
}
return nread;
}