diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-30 11:04:30 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-30 11:04:30 +0200 |
commit | 1fc261266766c3e7a50d6973eb38b744ab78085f (patch) | |
tree | e8efb46ddc049e875cb89783d0aebebd6a1942a2 /Kernel/FileSystem/DiskBackedFileSystem.cpp | |
parent | a61f6ccc2757b3b7711df5fd7374ae0fc0ac55d6 (diff) | |
download | serenity-1fc261266766c3e7a50d6973eb38b744ab78085f.zip |
Kernel: Make DiskBackedFS::read_block() write to client-provided memory
Instead of having DiskBackedFS allocate a ByteBuffer, leave it to each
client to provide buffer space.
This is significantly faster in many cases where we can use a stack
buffer and avoid heap allocation entirely.
Diffstat (limited to 'Kernel/FileSystem/DiskBackedFileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/DiskBackedFileSystem.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Kernel/FileSystem/DiskBackedFileSystem.cpp b/Kernel/FileSystem/DiskBackedFileSystem.cpp index 85b791adb2..9f1385fa57 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.cpp +++ b/Kernel/FileSystem/DiskBackedFileSystem.cpp @@ -107,7 +107,7 @@ bool DiskBackedFS::write_blocks(unsigned index, unsigned count, const ByteBuffer return true; } -ByteBuffer DiskBackedFS::read_block(unsigned index) const +bool DiskBackedFS::read_block(unsigned index, u8* buffer) const { #ifdef DBFS_DEBUG kprintf("DiskBackedFileSystem::read_block %u\n", index); @@ -120,27 +120,25 @@ ByteBuffer DiskBackedFS::read_block(unsigned index) const entry.has_data = true; ASSERT(success); } - return ByteBuffer::copy(entry.data, block_size()); + memcpy(buffer, entry.data, block_size()); + return true; } -ByteBuffer DiskBackedFS::read_blocks(unsigned index, unsigned count) const +bool DiskBackedFS::read_blocks(unsigned index, unsigned count, u8* buffer) const { if (!count) - return nullptr; + return false; if (count == 1) - return read_block(index); - auto blocks = ByteBuffer::create_uninitialized(count * block_size()); - u8* out = blocks.data(); + return read_block(index, buffer); + u8* out = buffer; for (unsigned i = 0; i < count; ++i) { - auto block = read_block(index + i); - if (!block) - return nullptr; - memcpy(out, block.data(), block.size()); + if (!read_block(index + i, out)) + return false; out += block_size(); } - return blocks; + return true; } void DiskBackedFS::flush_writes() |