1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibCore: Avoid a big malloc in CIODevice's internal buffering.

This heap allocation was totally avoidable and can be replaced by a stack
buffer instead. Dodges a bunch of mmap() traffic.
This commit is contained in:
Andreas Kling 2019-05-14 16:36:29 +02:00
parent 7c10a93d48
commit 1e0f9d325c

View file

@ -146,8 +146,8 @@ bool CIODevice::populate_read_buffer()
{
if (m_fd < 0)
return false;
auto buffer = ByteBuffer::create_uninitialized(PAGE_SIZE);
int nread = ::read(m_fd, buffer.pointer(), buffer.size());
byte buffer[1024];
int nread = ::read(m_fd, buffer, sizeof(buffer));
if (nread < 0) {
set_error(errno);
return false;
@ -156,8 +156,7 @@ bool CIODevice::populate_read_buffer()
set_eof(true);
return false;
}
buffer.trim(nread);
m_buffered_data.append(buffer.pointer(), buffer.size());
m_buffered_data.append(buffer, nread);
return true;
}