Skip to content

Commit d3fc5cf

Browse files
authored
[lldb] Remove redundant c_str() calls in stream output (NFC) (#94839)
Passing the result of c_str() to a stream is slow and redundant. This change removes unnecessary c_str() calls and uses the string object directly. Caught by cppcheck - lldb/tools/debugserver/source/JSON.cpp:398:19: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:408:64: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:420:54: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] lldb/tools/debugserver/source/JSON.cpp:46:13: performance: Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream] Fix #91212
1 parent 2fa14fc commit d3fc5cf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lldb/tools/debugserver/source/JSON.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ JSONString::JSONString(const std::string &s)
4343
: JSONValue(JSONValue::Kind::String), m_data(s) {}
4444

4545
void JSONString::Write(std::ostream &s) {
46-
s << "\"" << json_string_quote_metachars(m_data).c_str() << "\"";
46+
s << "\"" << json_string_quote_metachars(m_data) << "\"";
4747
}
4848

4949
uint64_t JSONNumber::GetAsUnsigned() const {
@@ -395,7 +395,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) {
395395
} else {
396396
error << "error: got exponent character but no exponent digits at "
397397
"offset in float value \""
398-
<< value.c_str() << "\"";
398+
<< value << "\"";
399399
value = error.str();
400400
return Token::Status;
401401
}
@@ -405,8 +405,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) {
405405
if (got_frac_digits) {
406406
return Token::Float;
407407
} else {
408-
error << "error: no digits after decimal point \"" << value.c_str()
409-
<< "\"";
408+
error << "error: no digits after decimal point \"" << value << "\"";
410409
value = error.str();
411410
return Token::Status;
412411
}
@@ -417,7 +416,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) {
417416
// We need at least some integer digits to make an integer
418417
return Token::Integer;
419418
} else {
420-
error << "error: no digits negate sign \"" << value.c_str() << "\"";
419+
error << "error: no digits negate sign \"" << value << "\"";
421420
value = error.str();
422421
return Token::Status;
423422
}

0 commit comments

Comments
 (0)