From c0a9db6d0fc92c50bc02d07bcb21c9e5869755ae Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Tue, 2 Aug 2022 12:30:18 +0200 Subject: [PATCH] logging: reserve space in buffer --- src/debug.cpp | 6 +++++- src/debug.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 258f824fc..31a2cb6f6 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -378,4 +378,8 @@ void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE * thread_local std::set Logger::oneshot_messages; -thread_local std::string Log_output::buffer; +thread_local std::string Log_output::buffer(initial_buf_size, '\0'); + +Log_output::Log_output(){ + last_msg.reserve(initial_buf_size); +} diff --git a/src/debug.h b/src/debug.h index 98d0322ad..9a9d62d11 100644 --- a/src/debug.h +++ b/src/debug.h @@ -145,7 +145,7 @@ class Log_output{ Log_output& lo; }; public: - Log_output() = default; + Log_output(); Buffer get_buffer() { return Buffer(*this); } @@ -164,6 +164,7 @@ public: private: void submit(); + constexpr static int initial_buf_size = 256; thread_local static std::string buffer; std::atomic skip_repeated;