AK: Simplify some stream reading logic

These do the same thing in a less convoluted way. NFC.
This commit is contained in:
Ali Mohammad Pur 2025-06-06 14:19:14 +02:00 committed by Ali Mohammad Pur
parent e260ba54e0
commit 0f13952f30
2 changed files with 4 additions and 13 deletions

View file

@ -17,13 +17,8 @@ ConstrainedStream::ConstrainedStream(MaybeOwned<Stream> stream, u64 limit)
ErrorOr<Bytes> ConstrainedStream::read_some(Bytes bytes)
{
if (bytes.size() >= m_limit)
bytes = bytes.trim(m_limit);
auto result = TRY(m_stream->read_some(bytes));
auto result = TRY(m_stream->read_some(bytes.trim(m_limit)));
m_limit -= result.size();
return result;
}

View file

@ -46,13 +46,9 @@ ErrorOr<void> FixedMemoryStream::truncate(size_t)
ErrorOr<Bytes> FixedMemoryStream::read_some(Bytes bytes)
{
auto to_read = min(remaining(), bytes.size());
if (to_read == 0)
return Bytes {};
m_bytes.slice(m_offset, to_read).copy_to(bytes);
m_offset += to_read;
return bytes.trim(to_read);
auto read = m_bytes.slice(m_offset).copy_trimmed_to(bytes);
m_offset += read;
return bytes.trim(read);
}
ErrorOr<void> FixedMemoryStream::read_until_filled(AK::Bytes bytes)