mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Optimize StorageDevice read and write function
Use shift operator with log size instead of division while calculating the index and len.
This commit is contained in:
parent
24c66b8442
commit
60aa4152e9
Notes:
sideshowbarker
2024-07-18 05:01:22 +09:00
Author: https://github.com/Panky-codes Commit: https://github.com/SerenityOS/serenity/commit/60aa4152e94 Pull-request: https://github.com/SerenityOS/serenity/pull/12198 Reviewed-by: https://github.com/IdanHo
1 changed files with 6 additions and 6 deletions
|
@ -29,9 +29,9 @@ StringView StorageDevice::class_name() const
|
|||
|
||||
ErrorOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKernelBuffer& outbuf, size_t len)
|
||||
{
|
||||
u64 index = offset / block_size();
|
||||
size_t whole_blocks = len / block_size();
|
||||
size_t remaining = len % block_size();
|
||||
u64 index = offset >> block_size_log();
|
||||
size_t whole_blocks = len >> block_size_log();
|
||||
size_t remaining = len - (whole_blocks << block_size_log());
|
||||
|
||||
// PATAChannel will chuck a wobbly if we try to read more than PAGE_SIZE
|
||||
// at a time, because it uses a single page for its DMA buffer.
|
||||
|
@ -91,9 +91,9 @@ bool StorageDevice::can_read(const OpenFileDescription&, u64 offset) const
|
|||
|
||||
ErrorOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const UserOrKernelBuffer& inbuf, size_t len)
|
||||
{
|
||||
u64 index = offset / block_size();
|
||||
size_t whole_blocks = len / block_size();
|
||||
size_t remaining = len % block_size();
|
||||
u64 index = offset >> block_size_log();
|
||||
size_t whole_blocks = len >> block_size_log();
|
||||
size_t remaining = len - (whole_blocks << block_size_log());
|
||||
|
||||
// PATAChannel will chuck a wobbly if we try to write more than PAGE_SIZE
|
||||
// at a time, because it uses a single page for its DMA buffer.
|
||||
|
|
Loading…
Reference in a new issue