Skip to content

Commit

Permalink
stdcxx: eliminate excessive use of std::string::c_str()
Browse files Browse the repository at this point in the history
It could be more clear and slightly more efficient not to convert an
`std::string` into a C-style string whenever possible.
  • Loading branch information
anpol authored and sergiud committed Dec 30, 2021
1 parent b3abfaa commit a8cfbe0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/googletest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ") ";
Expand Down Expand Up @@ -2290,7 +2290,7 @@ const vector<string>& 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
Expand Down

0 comments on commit a8cfbe0

Please sign in to comment.