From cd7596e67ec5f3021c94969b41fae05969267652 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 4 Oct 2018 23:55:50 -0400 Subject: [PATCH] text_formatter: Avoid unnecessary string temporary creation in PrintMessage() operator+ for std::string creates an entirely new string, which is kind of unnecessary here if we just want to append a null terminator to the existing one. Reduces the total amount of potential allocations that need to be done in the logging path. --- src/common/logging/text_formatter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index 8583916a8..2bfb6ce4b 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp @@ -31,7 +31,7 @@ std::string FormatLogMessage(const Entry& entry) { } void PrintMessage(const Entry& entry) { - auto str = FormatLogMessage(entry) + '\n'; + const auto str = FormatLogMessage(entry).append(1, '\n'); fputs(str.c_str(), stderr); }