Optionally skip copying into connection arena for appendMessage
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_; }
|
||||||
|
|||||||
Reference in New Issue
Block a user