mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
AK: Lower the requirements for InputStream::eof and rename it.
Consider the following snippet: void foo(InputStream& stream) { if(!stream.eof()) { u8 byte; stream >> byte; } } There is a very subtle bug in this snippet, for some input streams eof() might return false even if no more data can be read. In this case an error flag would be set on the stream. Until now I've always ensured that this is not the case, but this made the implementation of eof() unnecessarily complicated. InputFileStream::eof had to keep a ByteBuffer around just to make this possible. That meant a ton of unnecessary copies just to get a reliable eof(). In most cases it isn't actually necessary to have a reliable eof() implementation. In most other cases a reliable eof() is avaliable anyways because in some cases like InputMemoryStream it is very easy to implement.
This commit is contained in:
parent
8a21c528ad
commit
96edcbc27c
12 changed files with 61 additions and 89 deletions
|
@ -92,7 +92,8 @@ public:
|
|||
size_t read(Bytes) override;
|
||||
bool read_or_error(Bytes) override;
|
||||
bool discard_or_error(size_t) override;
|
||||
bool eof() const override;
|
||||
|
||||
bool unreliable_eof() const override;
|
||||
|
||||
static Optional<ByteBuffer> decompress_all(ReadonlyBytes);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue