Skip to content

Commit

Permalink
LibCore: Avoid a big malloc in CIODevice's internal buffering.
Browse files Browse the repository at this point in the history
This heap allocation was totally avoidable and can be replaced by a stack
buffer instead. Dodges a bunch of mmap() traffic.
  • Loading branch information
awesomekling committed May 14, 2019
1 parent 7c10a93 commit 1e0f9d3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions LibCore/CIODevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 1e0f9d3

Please sign in to comment.