From 0d688d9ce92d0e7ac356a6cce4e8d730c4069542 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Tue, 19 Aug 2025 13:44:16 -0400 Subject: [PATCH] Optionally skip copying into connection arena for appendMessage --- src/connection.cpp | 14 +++++++++----- src/connection.hpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 3267717..de3312f 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -27,10 +27,14 @@ Connection::~Connection() { } } -void Connection::appendMessage(std::string_view s) { - char *arena_str = arena_.allocate(s.size()); - std::memcpy(arena_str, s.data(), s.size()); - messages_.emplace_back(arena_str, s.size()); +void Connection::appendMessage(std::string_view s, bool copyToArena) { + if (copyToArena) { + char *arena_str = arena_.allocate(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*/, @@ -131,4 +135,4 @@ void Connection::tsan_release() { #if __has_feature(thread_sanitizer) tsan_sync_.store(0, std::memory_order_release); #endif -} \ No newline at end of file +} diff --git a/src/connection.hpp b/src/connection.hpp index ac6e783..a37e58c 100644 --- a/src/connection.hpp +++ b/src/connection.hpp @@ -40,7 +40,7 @@ struct Connection { ~Connection(); // 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; } ArenaAllocator &getArena() { return arena_; } int64_t getId() const { return id_; }