mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-24 18:28:57 +00:00
LibCore: Avoid some successive allocations in Stream::read_all()
For the general case, allocations will always have the size of a block. In case of a smaller read a block will be filled entirely before another allocation appends. It also adds a specialization for Stream::File::read_all() that tries to detect the size of the file with fstat to perform a single allocation.
This commit is contained in:
parent
3843b8c0a1
commit
e432a284d7
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/LucasChollet
Commit: e432a284d7
Pull-request: https://github.com/SerenityOS/serenity/pull/13870
Issue: https://github.com/SerenityOS/serenity/issues/5259
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/linusg
Reviewed-by: https://github.com/petelliott
2 changed files with 38 additions and 11 deletions
|
@ -37,7 +37,7 @@ public:
|
|||
/// Tries to fill the entire buffer through reading. Returns whether the
|
||||
/// buffer was filled without an error.
|
||||
virtual bool read_or_error(Bytes);
|
||||
ErrorOr<ByteBuffer> read_all();
|
||||
virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096);
|
||||
|
||||
virtual bool is_writable() const { return false; }
|
||||
/// Tries to write the entire contents of the buffer. It is possible for
|
||||
|
@ -62,6 +62,9 @@ public:
|
|||
virtual ~Stream()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
ErrorOr<ByteBuffer> read_all_impl(size_t block_size, size_t file_size = 0);
|
||||
};
|
||||
|
||||
enum class SeekMode {
|
||||
|
@ -197,6 +200,7 @@ public:
|
|||
|
||||
virtual bool is_readable() const override;
|
||||
virtual ErrorOr<Bytes> read(Bytes) override;
|
||||
virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096) override;
|
||||
virtual bool is_writable() const override;
|
||||
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
|
||||
virtual bool is_eof() const override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue