From 0cad2847f8c086d0bbf95329142a2cbb179f6d42 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 3 Dec 2015 14:08:06 -0800 Subject: [PATCH] LogFile pass references to reduce code size a bit. Apparently the compiler isn't optimizing away copies in places I thought it would. --- firmware/application/log_file.cpp | 6 +++--- firmware/application/log_file.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/application/log_file.cpp b/firmware/application/log_file.cpp index a32149f1..7bcfefbb 100644 --- a/firmware/application/log_file.cpp +++ b/firmware/application/log_file.cpp @@ -30,7 +30,7 @@ LogFile::~LogFile() { close(); } -bool LogFile::open_for_append(const std::string file_path) { +bool LogFile::open_for_append(const std::string& file_path) { const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS); if( open_result == FR_OK ) { const auto seek_result = f_lseek(&f, f_size(&f)); @@ -53,7 +53,7 @@ bool LogFile::is_ready() { return !f_error(&f); } -bool LogFile::write_entry(const rtc::RTC& datetime, const std::string entry) { +bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) { std::string timestamp = to_string_dec_uint(datetime.year(), 4, '0') + to_string_dec_uint(datetime.month(), 2, '0') + @@ -65,7 +65,7 @@ bool LogFile::write_entry(const rtc::RTC& datetime, const std::string entry) { return write(timestamp + " " + entry + "\r\n"); } -bool LogFile::write(const std::string message) { +bool LogFile::write(const std::string& message) { const auto puts_result = f_puts(message.c_str(), &f); const auto sync_result = f_sync(&f); return (puts_result >= 0) && (sync_result == FR_OK); diff --git a/firmware/application/log_file.hpp b/firmware/application/log_file.hpp index cf7dcf4d..3f7024c3 100644 --- a/firmware/application/log_file.hpp +++ b/firmware/application/log_file.hpp @@ -33,16 +33,16 @@ class LogFile { public: ~LogFile(); - bool open_for_append(const std::string file_path); + bool open_for_append(const std::string& file_path); bool close(); bool is_ready(); - bool write_entry(const rtc::RTC& datetime, const std::string entry); + bool write_entry(const rtc::RTC& datetime, const std::string& entry); private: FIL f; - bool write(const std::string message); + bool write(const std::string& message); }; #endif/*__LOG_FILE_H__*/