Optionally skip copying into connection arena for appendMessage

This commit is contained in:
2025-08-19 13:44:16 -04:00
parent 455ab749a6
commit 0d688d9ce9
2 changed files with 10 additions and 6 deletions

View File

@@ -27,10 +27,14 @@ Connection::~Connection() {
} }
} }
void Connection::appendMessage(std::string_view s) { void Connection::appendMessage(std::string_view s, bool copyToArena) {
char *arena_str = arena_.allocate<char>(s.size()); if (copyToArena) {
std::memcpy(arena_str, s.data(), s.size()); char *arena_str = arena_.allocate<char>(s.size());
messages_.emplace_back(arena_str, s.size()); std::memcpy(arena_str, s.data(), s.size());
messages_.emplace_back(arena_str, s.size());
} else {
messages_.push_back(s);
}
} }
std::string_view Connection::readBytes(size_t /*max_request_size*/, std::string_view Connection::readBytes(size_t /*max_request_size*/,
@@ -131,4 +135,4 @@ void Connection::tsan_release() {
#if __has_feature(thread_sanitizer) #if __has_feature(thread_sanitizer)
tsan_sync_.store(0, std::memory_order_release); tsan_sync_.store(0, std::memory_order_release);
#endif #endif
} }

View File

@@ -40,7 +40,7 @@ struct Connection {
~Connection(); ~Connection();
// Handler interface - public methods that handlers can use // Handler interface - public methods that handlers can use
void appendMessage(std::string_view s); void appendMessage(std::string_view s, bool copyToArena = true);
void closeAfterSend() { closeConnection_ = true; } void closeAfterSend() { closeConnection_ = true; }
ArenaAllocator &getArena() { return arena_; } ArenaAllocator &getArena() { return arena_; }
int64_t getId() const { return id_; } int64_t getId() const { return id_; }