avoid some unnecessary object creations and copies (#4493)
This commit is contained in:
parent
0481edf9c3
commit
eeb6db05f1
|
@ -341,10 +341,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
|
|||
{
|
||||
std::list<ErrorMessage::FileLocation> locationList;
|
||||
if (!filename.empty()) {
|
||||
ErrorMessage::FileLocation fileLoc;
|
||||
fileLoc.setfile(filename);
|
||||
fileLoc.line = lineNumber;
|
||||
locationList.push_back(std::move(fileLoc));
|
||||
locationList.emplace_back(filename, lineNumber);
|
||||
}
|
||||
|
||||
const ErrorMessage errmsg(locationList, emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
|
||||
|
|
|
@ -1476,9 +1476,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo
|
|||
|
||||
std::list<ErrorMessage::FileLocation> loclist;
|
||||
if (!file.empty()) {
|
||||
ErrorMessage::FileLocation location;
|
||||
location.setfile(file);
|
||||
loclist.push_back(std::move(location));
|
||||
loclist.emplace_back(file);
|
||||
}
|
||||
|
||||
std::ostringstream msg;
|
||||
|
@ -1514,9 +1512,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
|
|||
|
||||
std::list<ErrorMessage::FileLocation> loclist;
|
||||
if (!file.empty()) {
|
||||
ErrorMessage::FileLocation location;
|
||||
location.setfile(file);
|
||||
loclist.push_back(std::move(location));
|
||||
loclist.emplace_back(file);
|
||||
}
|
||||
|
||||
ErrorMessage errmsg(loclist,
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
FileLocation()
|
||||
: fileIndex(0), line(0), column(0) {}
|
||||
|
||||
FileLocation(const std::string &file, int line, unsigned int column)
|
||||
explicit FileLocation(const std::string &file, int line = 0, unsigned int column = 0)
|
||||
: fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file) {}
|
||||
|
||||
FileLocation(const std::string &file, std::string info, int line, unsigned int column)
|
||||
|
|
|
@ -301,7 +301,7 @@ struct ForwardTraversal {
|
|||
std::vector<ForwardTraversal> tryForkScope(Token* endBlock, bool isModified = false) {
|
||||
if (analyzer->updateScope(endBlock, isModified)) {
|
||||
ForwardTraversal ft = fork();
|
||||
return {ft};
|
||||
return {std::move(ft)};
|
||||
}
|
||||
return std::vector<ForwardTraversal> {};
|
||||
}
|
||||
|
|
|
@ -1645,9 +1645,9 @@ const Library::Container * getLibraryContainer(const Token * tok)
|
|||
return tok->valueType()->container;
|
||||
}
|
||||
|
||||
Library::TypeCheck Library::getTypeCheck(const std::string &check, const std::string &typeName) const
|
||||
Library::TypeCheck Library::getTypeCheck(std::string check, std::string typeName) const
|
||||
{
|
||||
auto it = mTypeChecks.find(std::pair<std::string, std::string>(check, typeName));
|
||||
auto it = mTypeChecks.find(std::pair<std::string, std::string>(std::move(check), std::move(typeName)));
|
||||
return it == mTypeChecks.end() ? TypeCheck::def : it->second;
|
||||
}
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ public:
|
|||
|
||||
/** Suppress/check a type */
|
||||
enum class TypeCheck { def, check, suppress };
|
||||
TypeCheck getTypeCheck(const std::string &check, const std::string &typeName) const;
|
||||
TypeCheck getTypeCheck(std::string check, std::string typeName) const;
|
||||
|
||||
private:
|
||||
// load a <function> xml node
|
||||
|
|
|
@ -3034,7 +3034,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
|||
Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok, const Token *argStart, const Token* funcStart)
|
||||
{
|
||||
Function function(mTokenizer, tok, scope, funcStart, argStart);
|
||||
scope->addFunction(function);
|
||||
scope->addFunction(std::move(function));
|
||||
return &scope->functionList.back();
|
||||
}
|
||||
|
||||
|
|
|
@ -6389,7 +6389,7 @@ struct SimpleConditionHandler : ConditionHandler {
|
|||
cond.false_values.emplace_back(tok, 0LL);
|
||||
cond.vartok = vartok;
|
||||
|
||||
return {cond};
|
||||
return {std::move(cond)};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6574,8 +6574,8 @@ struct SymbolicConditionHandler : SimpleConditionHandler {
|
|||
setSymbolic(false_value, valuetok);
|
||||
|
||||
Condition cond;
|
||||
cond.true_values = {true_value};
|
||||
cond.false_values = {false_value};
|
||||
cond.true_values = {std::move(true_value)};
|
||||
cond.false_values = {std::move(false_value)};
|
||||
cond.vartok = vartok;
|
||||
cond.inverted = inverted;
|
||||
result.push_back(std::move(cond));
|
||||
|
@ -7977,7 +7977,7 @@ struct IteratorConditionHandler : SimpleConditionHandler {
|
|||
cond.false_values = values;
|
||||
}
|
||||
|
||||
return {cond};
|
||||
return {std::move(cond)};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -8308,7 +8308,7 @@ struct ContainerConditionHandler : ConditionHandler {
|
|||
cond.false_values.emplace_back(std::move(value));
|
||||
cond.vartok = vartok;
|
||||
cond.inverted = true;
|
||||
return {cond};
|
||||
return {std::move(cond)};
|
||||
}
|
||||
// String compare
|
||||
if (Token::Match(tok, "==|!=")) {
|
||||
|
@ -8331,7 +8331,7 @@ struct ContainerConditionHandler : ConditionHandler {
|
|||
cond.true_values.emplace_back(std::move(value));
|
||||
cond.vartok = vartok;
|
||||
cond.impossible = false;
|
||||
return {cond};
|
||||
return {std::move(cond)};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -8965,6 +8965,7 @@ const ValueFlow::Value* ValueFlow::findValue(const std::list<ValueFlow::Value>&
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TODO: returns a single value at most - no need for std::vector
|
||||
static std::vector<ValueFlow::Value> isOutOfBoundsImpl(const ValueFlow::Value& size,
|
||||
const Token* indexTok,
|
||||
bool condition)
|
||||
|
@ -8996,9 +8997,10 @@ static std::vector<ValueFlow::Value> isOutOfBoundsImpl(const ValueFlow::Value& s
|
|||
return {};
|
||||
value.intvalue = size.intvalue;
|
||||
value.bound = ValueFlow::Value::Bound::Lower;
|
||||
return {value};
|
||||
return {std::move(value)};
|
||||
}
|
||||
|
||||
// TODO: return single value at most - no need for std::vector
|
||||
std::vector<ValueFlow::Value> ValueFlow::isOutOfBounds(const Value& size, const Token* indexTok, bool possible)
|
||||
{
|
||||
ValueFlow::Value inBoundsValue = inferCondition("<", indexTok, size.intvalue);
|
||||
|
|
Loading…
Reference in New Issue