LogFile pass references to reduce code size a bit.

Apparently the compiler isn't optimizing away copies in places I thought it would.
This commit is contained in:
Jared Boone 2015-12-03 14:08:06 -08:00
parent bb3cb6f080
commit 0cad2847f8
2 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ LogFile::~LogFile() {
close(); 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); const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS);
if( open_result == FR_OK ) { if( open_result == FR_OK ) {
const auto seek_result = f_lseek(&f, f_size(&f)); const auto seek_result = f_lseek(&f, f_size(&f));
@ -53,7 +53,7 @@ bool LogFile::is_ready() {
return !f_error(&f); 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 = std::string timestamp =
to_string_dec_uint(datetime.year(), 4, '0') + to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '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"); 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 puts_result = f_puts(message.c_str(), &f);
const auto sync_result = f_sync(&f); const auto sync_result = f_sync(&f);
return (puts_result >= 0) && (sync_result == FR_OK); return (puts_result >= 0) && (sync_result == FR_OK);

View File

@ -33,16 +33,16 @@ class LogFile {
public: public:
~LogFile(); ~LogFile();
bool open_for_append(const std::string file_path); bool open_for_append(const std::string& file_path);
bool close(); bool close();
bool is_ready(); 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: private:
FIL f; FIL f;
bool write(const std::string message); bool write(const std::string& message);
}; };
#endif/*__LOG_FILE_H__*/ #endif/*__LOG_FILE_H__*/