From a8cfbe0c0c5622621d04c34d04845b1b243b32d7 Mon Sep 17 00:00:00 2001 From: Andrei Polushin Date: Thu, 30 Dec 2021 15:41:08 +0700 Subject: [PATCH] stdcxx: eliminate excessive use of std::string::c_str() It could be more clear and slightly more efficient not to convert an `std::string` into a C-style string whenever possible. --- src/googletest.h | 2 +- src/logging.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/googletest.h b/src/googletest.h index f06be84..51e05dc 100644 --- a/src/googletest.h +++ b/src/googletest.h @@ -467,7 +467,7 @@ static inline void StringReplace(string* str, const string& newsub) { size_t pos = str->find(oldsub); if (pos != string::npos) { - str->replace(pos, oldsub.size(), newsub.c_str()); + str->replace(pos, oldsub.size(), newsub); } } diff --git a/src/logging.cc b/src/logging.cc index 77941f4..7a64a78 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -1662,7 +1662,7 @@ void LogMessage::Init(const char* file, char fileline[128]; snprintf(fileline, sizeof(fileline), "%s:%d", data_->basename_, line); #ifdef HAVE_STACKTRACE - if (!strcmp(FLAGS_log_backtrace_at.c_str(), fileline)) { + if (FLAGS_log_backtrace_at == fileline) { string stacktrace; DumpStackTraceToString(&stacktrace); stream() << " (stacktrace:\n" << stacktrace << ") "; @@ -2290,7 +2290,7 @@ const vector& GetLoggingDirectories() { if ( !FLAGS_log_dir.empty() ) { // A dir was specified, we should use it - logging_directories_list->push_back(FLAGS_log_dir.c_str()); + logging_directories_list->push_back(FLAGS_log_dir); } else { GetTempDirectories(logging_directories_list); #ifdef GLOG_OS_WINDOWS