From 682de0a2ade5a9d8247d27b867386f7f2b4cf42c Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 19 Aug 2021 22:09:11 +0100 Subject: [PATCH] Made the timezone abbreviation static in the Logger, as it will rarely change throughout an execution cycle and was surprisingly resulting in too many memory allocations. --- src/Logger/Logger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Logger/Logger.cpp b/src/Logger/Logger.cpp index 17c3f3f0..30d4af01 100644 --- a/src/Logger/Logger.cpp +++ b/src/Logger/Logger.cpp @@ -9,12 +9,12 @@ void Logger::log(const std::string& message, LogLevel logLevel, bool print) { auto logEntry = LogEntry(message, logLevel); Logger::logEntries.push_back(logEntry); auto index = Logger::logEntries.size(); + static auto timezoneAbbreviation = DateTime::getTimeZoneAbbreviation(logEntry.timestamp).toStdString(); if (print) { // Print the timestamp and index in a green font color: std::cout << "\033[32m"; - std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString() + - DateTime::getTimeZoneAbbreviation(logEntry.timestamp).toStdString(); + std::cout << logEntry.timestamp.toString("yyyy-MM-dd hh:mm:ss ").toStdString() + timezoneAbbreviation; if (!logEntry.threadName.empty()) { std::cout << " [" << logEntry.threadName << "]";