mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:17:34 +00:00
LibIPC: Avoid redundant copy of every tranferred IPC message
For every IPC message sent, we currently prepend the message size to the IPC message buffer. This incurs the cost of copying the entire message to its newly allocated position. Instead, reserve the bytes for the size at the front of the buffer upon creation. Prevent dangerous access to the buffer with specific public methods.
This commit is contained in:
parent
f2db700ae7
commit
34160743dc
4 changed files with 48 additions and 14 deletions
|
@ -37,20 +37,20 @@ public:
|
|||
|
||||
ErrorOr<void> extend_capacity(size_t capacity)
|
||||
{
|
||||
return m_buffer.data.try_ensure_capacity(m_buffer.data.size() + capacity);
|
||||
TRY(m_buffer.extend_data_capacity(capacity));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> append(u8 const* values, size_t count)
|
||||
{
|
||||
TRY(extend_capacity(count));
|
||||
m_buffer.data.unchecked_append(values, count);
|
||||
TRY(m_buffer.append_data(values, count));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> append_file_descriptor(int fd)
|
||||
{
|
||||
auto auto_fd = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AutoCloseFileDescriptor(fd)));
|
||||
return m_buffer.fds.try_append(move(auto_fd));
|
||||
TRY(m_buffer.append_file_descriptor(fd));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> encode_size(size_t size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue