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

LibTLS: Add segmentation to the application buffer to avoid memcpy churn

We were previously doing a *lot* of unnecessary memcpy work when
transferring large files.

This patch addresses the issue by introducing a simple segmented buffer
with no additional work when appending new data, or when transfering out
of the buffer.
This commit is contained in:
Andreas Kling 2024-01-03 10:53:51 +01:00
parent 40f87f0954
commit 27a294547d
3 changed files with 42 additions and 4 deletions

View file

@ -27,8 +27,7 @@ ErrorOr<Bytes> TLSv12::read_some(Bytes bytes)
return Bytes {};
}
TRY(m_context.application_buffer.slice(0, size_to_read)).span().copy_to(bytes);
m_context.application_buffer = TRY(m_context.application_buffer.slice(size_to_read, m_context.application_buffer.size() - size_to_read));
m_context.application_buffer.transfer(bytes, size_to_read);
return Bytes { bytes.data(), size_to_read };
}