Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit a8cfbe0

Browse files
anpolsergiud
authored andcommitted
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.
1 parent b3abfaa commit a8cfbe0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/googletest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static inline void StringReplace(string* str,
467467
const string& newsub) {
468468
size_t pos = str->find(oldsub);
469469
if (pos != string::npos) {
470-
str->replace(pos, oldsub.size(), newsub.c_str());
470+
str->replace(pos, oldsub.size(), newsub);
471471
}
472472
}
473473

src/logging.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ void LogMessage::Init(const char* file,
16621662
char fileline[128];
16631663
snprintf(fileline, sizeof(fileline), "%s:%d", data_->basename_, line);
16641664
#ifdef HAVE_STACKTRACE
1665-
if (!strcmp(FLAGS_log_backtrace_at.c_str(), fileline)) {
1665+
if (FLAGS_log_backtrace_at == fileline) {
16661666
string stacktrace;
16671667
DumpStackTraceToString(&stacktrace);
16681668
stream() << " (stacktrace:\n" << stacktrace << ") ";
@@ -2290,7 +2290,7 @@ const vector<string>& GetLoggingDirectories() {
22902290

22912291
if ( !FLAGS_log_dir.empty() ) {
22922292
// A dir was specified, we should use it
2293-
logging_directories_list->push_back(FLAGS_log_dir.c_str());
2293+
logging_directories_list->push_back(FLAGS_log_dir);
22942294
} else {
22952295
GetTempDirectories(logging_directories_list);
22962296
#ifdef GLOG_OS_WINDOWS

0 commit comments

Comments
 (0)