From 5c86147ef4e2e0f5d622941c34764f2b5a9a439c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Apr 2021 12:57:45 -0400 Subject: [PATCH] log/backend: Use in-class initializer for FileBackend We can also avoid redundant constructions of the same string repeatedly. --- src/common/logging/backend.cpp | 10 ++++++---- src/common/logging/backend.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index f47e2368f4..cdfa0964a6 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -145,12 +145,14 @@ void LogcatBackend::Write(const Entry& entry) { PrintMessageToLogcat(entry); } -FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { - if (FileUtil::Exists(filename + ".old.txt")) { - FileUtil::Delete(filename + ".old.txt"); +FileBackend::FileBackend(const std::string& filename) { + const auto old_filename = filename + ".old.txt"; + + if (FileUtil::Exists(old_filename)) { + FileUtil::Delete(old_filename); } if (FileUtil::Exists(filename)) { - FileUtil::Rename(filename, filename + ".old.txt"); + FileUtil::Rename(filename, old_filename); } // _SH_DENYWR allows read only access to the file for other programs. diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index eeb360aa49..b9e5386a07 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -109,7 +109,7 @@ public: private: FileUtil::IOFile file; - std::size_t bytes_written; + std::size_t bytes_written = 0; }; /**