Skip to content

Commit d44879f

Browse files
committed
fixed performance-faster-string-find clang-tidy warnings
1 parent 135bc2e commit d44879f

15 files changed

Lines changed: 62 additions & 62 deletions

cli/cmdlineparser.cpp

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

453453
if (!mSettings.userDefines.empty())
454-
mSettings.userDefines += ";";
454+
mSettings.userDefines += ';';
455455
mSettings.userDefines += define;
456456
}
457457

@@ -1145,7 +1145,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11451145
if (std::strcmp(argv[i], "--premium=safety") == 0)
11461146
mSettings.safety = true;
11471147
if (!mSettings.premiumArgs.empty())
1148-
mSettings.premiumArgs += " ";
1148+
mSettings.premiumArgs += ' ';
11491149
const std::string p(argv[i] + 10);
11501150
const std::string p2(p.find('=') != std::string::npos ? p.substr(0, p.find('=')) : "");
11511151
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
@@ -695,7 +695,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
695695
std::string joinedArgs;
696696
for (const std::string &arg : args) {
697697
if (!joinedArgs.empty())
698-
joinedArgs += " ";
698+
joinedArgs += ' ';
699699
if (arg.find(' ') != std::string::npos)
700700
joinedArgs += '"' + arg + '"';
701701
else

cli/processexecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ namespace {
125125
static std::string suppressionToString(const SuppressionList::Suppression &suppr)
126126
{
127127
std::string suppr_str = suppr.toString();
128-
suppr_str += ";";
128+
suppr_str += ';';
129129
suppr_str += std::to_string(suppr.column);
130-
suppr_str += ";";
130+
suppr_str += ';';
131131
suppr_str += suppr.checked ? "1" : "0";
132-
suppr_str += ";";
132+
suppr_str += ';';
133133
suppr_str += suppr.matched ? "1" : "0";
134-
suppr_str += ";";
134+
suppr_str += ';';
135135
suppr_str += suppr.extraComment;
136136
return suppr_str;
137137
}

lib/checkclass.cpp

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

22992299
if (func.tokenDef->str() == "(")
2300-
functionName += ")";
2300+
functionName += ')';
23012301
else if (func.tokenDef->str() == "[")
2302-
functionName += "]";
2302+
functionName += ']';
23032303

23042304
if (func.isInline())
23052305
checkConstError(func.token, classname, functionName, suggestStatic, foundAllBaseClasses);

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4138,7 +4138,7 @@ void CheckOtherImpl::funcArgOrderDifferent(const std::string & functionName,
41384138
if (definitions[i])
41394139
msg += definitions[i]->str();
41404140
}
4141-
msg += "'";
4141+
msg += '\'';
41424142
reportError(tokens, Severity::warning, "funcArgOrderDifferent", msg, CWE683, Certainty::normal);
41434143
}
41444144

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
@@ -1423,7 +1423,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
14231423
// Write all tokens in a string that can be parsed by pcre
14241424
std::string str;
14251425
for (const Token *tok = list.front(); tok; tok = tok->next()) {
1426-
str += " ";
1426+
str += ' ';
14271427
str += tok->str();
14281428
}
14291429

@@ -1919,7 +1919,7 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string
19191919

19201920
dumpProlog += "str=\"";
19211921
dumpProlog += ErrorLogger::toxml(tok->str());
1922-
dumpProlog += "\"";
1922+
dumpProlog += '"';
19231923

19241924
dumpProlog += "/>\n";
19251925
}

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
@@ -781,8 +781,8 @@ std::set<std::string> Preprocessor::getConfigs() const
781781
// Insert library defines
782782
for (const auto &define : mSettings.library.defines()) {
783783

784-
const std::string::size_type paren = define.find("(");
785-
const std::string::size_type space = define.find(" ");
784+
const std::string::size_type paren = define.find('(');
785+
const std::string::size_type space = define.find(' ');
786786
std::string::size_type end = space;
787787

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

lib/symboldatabase.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,7 @@ std::string Function::fullName() const
29372937
if (!s->className.empty())
29382938
ret = s->className + "::" + ret;
29392939
}
2940-
ret += "(";
2940+
ret += '(';
29412941
for (const Variable &a : argumentList)
29422942
ret += (a.index() == 0 ? "" : ",") + a.name();
29432943
return ret + ")";
@@ -3000,7 +3000,7 @@ static bool usingNamespace(const Scope *scope, const Token *first, const Token *
30003000
std::string nsName;
30013001
while (start && start->str() != ";") {
30023002
if (!nsName.empty())
3003-
nsName += " ";
3003+
nsName += ' ';
30043004
nsName += start->str();
30053005
start = start->next();
30063006
}
@@ -4442,14 +4442,14 @@ void SymbolDatabase::printXml(std::ostream &out) const
44424442
outs += " <scope";
44434443
outs += " id=\"";
44444444
outs += id_string(&*scope);
4445-
outs += "\"";
4445+
outs += '"';
44464446
outs += " type=\"";
44474447
outs += scopeTypeToString(scope->type);
4448-
outs += "\"";
4448+
outs += '"';
44494449
if (!scope->className.empty()) {
44504450
outs += " className=\"";
44514451
outs += ErrorLogger::toxml(scope->className);
4452-
outs += "\"";
4452+
outs += '"';
44534453
}
44544454
if (scope->bodyStart) {
44554455
outs += " bodyStart=\"";
@@ -4464,17 +4464,17 @@ void SymbolDatabase::printXml(std::ostream &out) const
44644464
if (scope->nestedIn) {
44654465
outs += " nestedIn=\"";
44664466
outs += id_string(scope->nestedIn);
4467-
outs += "\"";
4467+
outs += '"';
44684468
}
44694469
if (scope->function) {
44704470
outs += " function=\"";
44714471
outs += id_string(scope->function);
4472-
outs += "\"";
4472+
outs += '"';
44734473
}
44744474
if (scope->definedType) {
44754475
outs += " definedType=\"";
44764476
outs += id_string(scope->definedType);
4477-
outs += "\"";
4477+
outs += '"';
44784478
}
44794479
if (scope->functionList.empty() && scope->varlist.empty())
44804480
outs += "/>\n";
@@ -4504,7 +4504,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
45044504
if (function->access == AccessControl::Public || function->access == AccessControl::Protected || function->access == AccessControl::Private) {
45054505
outs += " access=\"";
45064506
outs += accessControlToString(function->access);
4507-
outs +="\"";
4507+
outs += '"';
45084508
}
45094509
if (function->isOperator())
45104510
outs += " isOperator=\"true\"";
@@ -4525,7 +4525,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
45254525
if (const Function* overriddenFunction = function->getOverriddenFunction()) {
45264526
outs += " overriddenFunction=\"";
45274527
outs += id_string(overriddenFunction);
4528-
outs += "\"";
4528+
outs += '"';
45294529
}
45304530
if (function->isAttributeConst())
45314531
outs += " isAttributeConst=\"true\"";
@@ -4570,7 +4570,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
45704570
outs += id_string(&type);
45714571
outs += "\" classScope=\"";
45724572
outs += id_string(type.classScope);
4573-
outs += "\"";
4573+
outs += '"';
45744574
if (type.derivedFrom.empty()) {
45754575
outs += "/>\n";
45764576
continue;
@@ -4580,16 +4580,16 @@ void SymbolDatabase::printXml(std::ostream &out) const
45804580
outs += " <derivedFrom";
45814581
outs += " access=\"";
45824582
outs += accessControlToString(baseInfo.access);
4583-
outs += "\"";
4583+
outs += '"';
45844584
outs += " type=\"";
45854585
outs += id_string(baseInfo.type);
4586-
outs += "\"";
4586+
outs += '"';
45874587
outs += " isVirtual=\"";
45884588
outs += bool_to_string(baseInfo.isVirtual);
4589-
outs += "\"";
4589+
outs += '"';
45904590
outs += " nameTok=\"";
45914591
outs += id_string(baseInfo.nameTok);
4592-
outs += "\"";
4592+
outs += '"';
45934593
outs += "/>\n";
45944594
}
45954595
outs += " </type>\n";
@@ -5964,7 +5964,7 @@ static std::string getTypeString(const Token *typeToken)
59645964
if (typeToken->str() == "<") {
59655965
for (const Token *tok = typeToken; tok != typeToken->link(); tok = tok->next())
59665966
ret += tok->str();
5967-
ret += ">";
5967+
ret += '>';
59685968
typeToken = typeToken->link()->next();
59695969
}
59705970
}
@@ -8352,7 +8352,7 @@ std::string ValueType::dump() const
83528352
ret += "valueType-type=\"container\"";
83538353
ret += " valueType-containerId=\"";
83548354
ret += id_string(container);
8355-
ret += "\"";
8355+
ret += '"';
83568356
break;
83578357
}
83588358
case ITERATOR:

0 commit comments

Comments
 (0)