Don't copy every byte read into arena
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user