Don't copy every byte read into arena

This commit is contained in:
2025-08-20 15:21:15 -04:00
parent 7f4c024efa
commit 60cda698c0
3 changed files with 6 additions and 14 deletions

View File

@@ -47,11 +47,7 @@ void Connection::appendMessage(std::string_view s, bool copyToArena) {
}
}
std::string_view Connection::readBytes(size_t /*max_request_size*/,
size_t buffer_size) {
// Use Variable Length Array for optimal stack allocation
char buf[buffer_size];
std::string_view Connection::readBytes(char *buf, size_t buffer_size) {
int r = read(fd_, buf, buffer_size);
if (r == -1) {
if (errno == EINTR || errno == EAGAIN) {
@@ -63,11 +59,7 @@ std::string_view Connection::readBytes(size_t /*max_request_size*/,
if (r == 0) {
return {}; // EOF - let server handle connection cleanup
}
// Copy data to arena for persistent storage
char *arena_data = arena_.allocate<char>(r);
std::memcpy(arena_data, buf, r);
return {arena_data, size_t(r)};
return {buf, size_t(r)};
}
bool Connection::writeBytes() {