Skip to content

Commit b84e207

Browse files
committed
fixed performance-faster-string-find clang-tidy warnings
1 parent d5cdce8 commit b84e207

15 files changed

Lines changed: 61 additions & 61 deletions

cli/cmdlineparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
452452
define += "=1";
453453

454454
if (!mSettings.userDefines.empty())
455-
mSettings.userDefines += ";";
455+
mSettings.userDefines += ';';
456456
mSettings.userDefines += define;
457457
}
458458

@@ -1134,7 +1134,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11341134
if (std::strcmp(argv[i], "--premium=safety") == 0)
11351135
mSettings.safety = true;
11361136
if (!mSettings.premiumArgs.empty())
1137-
mSettings.premiumArgs += " ";
1137+
mSettings.premiumArgs += ' ';
11381138
const std::string p(argv[i] + 10);
11391139
const std::string p2(p.find('=') != std::string::npos ? p.substr(0, p.find('=')) : "");
11401140
const bool isCodingStandard = startsWith(p, "autosar") || startsWith(p,"cert-") || startsWith(p,"misra-") || p == "safety-profiles";

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
683683
std::string joinedArgs;
684684
for (const std::string &arg : args) {
685685
if (!joinedArgs.empty())
686-
joinedArgs += " ";
686+
joinedArgs += ' ';
687687
if (arg.find(' ') != std::string::npos)
688688
joinedArgs += '"' + arg + '"';
689689
else

cli/processexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ namespace {
112112
static std::string suppressionToString(const SuppressionList::Suppression &suppr)
113113
{
114114
std::string suppr_str = suppr.toString();
115-
suppr_str += ";";
115+
suppr_str += ';';
116116
suppr_str += suppr.checked ? "1" : "0";
117-
suppr_str += ";";
117+
suppr_str += ';';
118118
suppr_str += suppr.matched ? "1" : "0";
119-
suppr_str += ";";
119+
suppr_str += ';';
120120
suppr_str += suppr.extraComment;
121121
return suppr_str;
122122
}

lib/checkclass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,9 +2241,9 @@ void CheckClass::checkConst()
22412241
std::string functionName = (func.tokenDef->isName() ? "" : "operator") + func.tokenDef->str();
22422242

22432243
if (func.tokenDef->str() == "(")
2244-
functionName += ")";
2244+
functionName += ')';
22452245
else if (func.tokenDef->str() == "[")
2246-
functionName += "]";
2246+
functionName += ']';
22472247

22482248
if (func.isInline())
22492249
checkConstError(func.token, classname, functionName, suggestStatic, foundAllBaseClasses);

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4104,7 +4104,7 @@ void CheckOther::funcArgOrderDifferent(const std::string & functionName,
41044104
if (definitions[i])
41054105
msg += definitions[i]->str();
41064106
}
4107-
msg += "'";
4107+
msg += '\'';
41084108
reportError(tokens, Severity::warning, "funcArgOrderDifferent", msg, CWE683, Certainty::normal);
41094109
}
41104110

lib/clangimport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ std::string clangimport::AstNode::getTemplateParameters() const
494494
if (templateParameters.empty())
495495
templateParameters = "<";
496496
else
497-
templateParameters += ",";
497+
templateParameters += ',';
498498
templateParameters += unquote(child->mExtTokens.back());
499499
}
500500
}
@@ -617,7 +617,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList &tokenList, const s
617617

618618
if (type.find("(*)(") != std::string::npos) {
619619
type.erase(type.find("(*)("));
620-
type += "*";
620+
type += '*';
621621
}
622622
if (type.find('(') != std::string::npos)
623623
type.erase(type.find('('));

lib/cppcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
14251425
// Write all tokens in a string that can be parsed by pcre
14261426
std::string str;
14271427
for (const Token *tok = list.front(); tok; tok = tok->next()) {
1428-
str += " ";
1428+
str += ' ';
14291429
str += tok->str();
14301430
}
14311431

@@ -1924,7 +1924,7 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string
19241924

19251925
dumpProlog += "str=\"";
19261926
dumpProlog += ErrorLogger::toxml(tok->str());
1927-
dumpProlog += "\"";
1927+
dumpProlog += '"';
19281928

19291929
dumpProlog += "/>\n";
19301930
}

lib/errorlogger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void ErrorMessage::setmsg(const std::string &msg)
247247
static void serializeString(std::string &oss, const std::string & str)
248248
{
249249
oss += std::to_string(str.length());
250-
oss += " ";
250+
oss += ' ';
251251
oss += str;
252252
}
253253

@@ -296,7 +296,7 @@ std::string ErrorMessage::serialize() const
296296
serializeString(oss, saneVerboseMessage);
297297
serializeString(oss, mSymbolNames);
298298
oss += std::to_string(callStack.size());
299-
oss += " ";
299+
oss += ' ';
300300

301301
for (auto loc = callStack.cbegin(); loc != callStack.cend(); ++loc) {
302302
std::string frame;

lib/preprocessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,8 @@ std::set<std::string> Preprocessor::getConfigs() const
777777
// Insert library defines
778778
for (const auto &define : mSettings.library.defines()) {
779779

780-
const std::string::size_type paren = define.find("(");
781-
const std::string::size_type space = define.find(" ");
780+
const std::string::size_type paren = define.find('(');
781+
const std::string::size_type space = define.find(' ');
782782
std::string::size_type end = space;
783783

784784
if (paren != std::string::npos && paren < space)

lib/symboldatabase.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,7 @@ std::string Function::fullName() const
29262926
if (!s->className.empty())
29272927
ret = s->className + "::" + ret;
29282928
}
2929-
ret += "(";
2929+
ret += '(';
29302930
for (const Variable &a : argumentList)
29312931
ret += (a.index() == 0 ? "" : ",") + a.name();
29322932
return ret + ")";
@@ -2989,7 +2989,7 @@ static bool usingNamespace(const Scope *scope, const Token *first, const Token *
29892989
std::string nsName;
29902990
while (start && start->str() != ";") {
29912991
if (!nsName.empty())
2992-
nsName += " ";
2992+
nsName += ' ';
29932993
nsName += start->str();
29942994
start = start->next();
29952995
}
@@ -4431,14 +4431,14 @@ void SymbolDatabase::printXml(std::ostream &out) const
44314431
outs += " <scope";
44324432
outs += " id=\"";
44334433
outs += id_string(&*scope);
4434-
outs += "\"";
4434+
outs += '"';
44354435
outs += " type=\"";
44364436
outs += scopeTypeToString(scope->type);
4437-
outs += "\"";
4437+
outs += '"';
44384438
if (!scope->className.empty()) {
44394439
outs += " className=\"";
44404440
outs += ErrorLogger::toxml(scope->className);
4441-
outs += "\"";
4441+
outs += '"';
44424442
}
44434443
if (scope->bodyStart) {
44444444
outs += " bodyStart=\"";
@@ -4453,17 +4453,17 @@ void SymbolDatabase::printXml(std::ostream &out) const
44534453
if (scope->nestedIn) {
44544454
outs += " nestedIn=\"";
44554455
outs += id_string(scope->nestedIn);
4456-
outs += "\"";
4456+
outs += '"';
44574457
}
44584458
if (scope->function) {
44594459
outs += " function=\"";
44604460
outs += id_string(scope->function);
4461-
outs += "\"";
4461+
outs += '"';
44624462
}
44634463
if (scope->definedType) {
44644464
outs += " definedType=\"";
44654465
outs += id_string(scope->definedType);
4466-
outs += "\"";
4466+
outs += '"';
44674467
}
44684468
if (scope->functionList.empty() && scope->varlist.empty())
44694469
outs += "/>\n";
@@ -4493,7 +4493,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
44934493
if (function->access == AccessControl::Public || function->access == AccessControl::Protected || function->access == AccessControl::Private) {
44944494
outs += " access=\"";
44954495
outs += accessControlToString(function->access);
4496-
outs +="\"";
4496+
outs += '"';
44974497
}
44984498
if (function->isOperator())
44994499
outs += " isOperator=\"true\"";
@@ -4514,7 +4514,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
45144514
if (const Function* overriddenFunction = function->getOverriddenFunction()) {
45154515
outs += " overriddenFunction=\"";
45164516
outs += id_string(overriddenFunction);
4517-
outs += "\"";
4517+
outs += '"';
45184518
}
45194519
if (function->isAttributeConst())
45204520
outs += " isAttributeConst=\"true\"";
@@ -4559,7 +4559,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
45594559
outs += id_string(&type);
45604560
outs += "\" classScope=\"";
45614561
outs += id_string(type.classScope);
4562-
outs += "\"";
4562+
outs += '"';
45634563
if (type.derivedFrom.empty()) {
45644564
outs += "/>\n";
45654565
continue;
@@ -4569,16 +4569,16 @@ void SymbolDatabase::printXml(std::ostream &out) const
45694569
outs += " <derivedFrom";
45704570
outs += " access=\"";
45714571
outs += accessControlToString(baseInfo.access);
4572-
outs += "\"";
4572+
outs += '"';
45734573
outs += " type=\"";
45744574
outs += id_string(baseInfo.type);
4575-
outs += "\"";
4575+
outs += '"';
45764576
outs += " isVirtual=\"";
45774577
outs += bool_to_string(baseInfo.isVirtual);
4578-
outs += "\"";
4578+
outs += '"';
45794579
outs += " nameTok=\"";
45804580
outs += id_string(baseInfo.nameTok);
4581-
outs += "\"";
4581+
outs += '"';
45824582
outs += "/>\n";
45834583
}
45844584
outs += " </type>\n";
@@ -5954,7 +5954,7 @@ static std::string getTypeString(const Token *typeToken)
59545954
if (typeToken->str() == "<") {
59555955
for (const Token *tok = typeToken; tok != typeToken->link(); tok = tok->next())
59565956
ret += tok->str();
5957-
ret += ">";
5957+
ret += '>';
59585958
typeToken = typeToken->link()->next();
59595959
}
59605960
}
@@ -8339,7 +8339,7 @@ std::string ValueType::dump() const
83398339
ret += "valueType-type=\"container\"";
83408340
ret += " valueType-containerId=\"";
83418341
ret += id_string(container);
8342-
ret += "\"";
8342+
ret += '"';
83438343
break;
83448344
}
83458345
case ITERATOR:

0 commit comments

Comments
 (0)