Prevent copying in range-based for loops (#2751)

Use reference types in range for loops to prevent copying.
This commit is contained in:
Georgy Komarov 2020-08-23 21:53:44 +03:00 committed by GitHub
parent 2bb73840fc
commit c5369b84e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -1173,7 +1173,7 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string>
output->clear(); output->clear();
std::string joinedArgs; std::string joinedArgs;
for (const std::string arg: args) { for (const std::string &arg : args) {
if (!joinedArgs.empty()) if (!joinedArgs.empty())
joinedArgs += " "; joinedArgs += " ";
joinedArgs += arg; joinedArgs += arg;

View File

@ -588,7 +588,7 @@ namespace {
std::string str() const { std::string str() const {
std::ostringstream ret; std::ostringstream ret;
std::map<std::string, ExprEngine::ValuePtr> vars; std::map<std::string, ExprEngine::ValuePtr> vars;
for (const auto mem: memory) { for (const auto &mem: memory) {
if (!mem.second) if (!mem.second)
continue; continue;
const Variable *var = tokenizer->getSymbolDatabase()->getVariableFromVarId(mem.first); const Variable *var = tokenizer->getSymbolDatabase()->getVariableFromVarId(mem.first);
@ -597,11 +597,11 @@ namespace {
ret << " @" << mem.first << ":" << mem.second->name; ret << " @" << mem.first << ":" << mem.second->name;
getSymbols(vars, mem.second); getSymbols(vars, mem.second);
} }
for (const auto var: vars) { for (const auto &var: vars) {
if (var.second->name[0] == '$') if (var.second->name[0] == '$')
ret << " " << ::str(var.second); ret << " " << ::str(var.second);
} }
for (const auto c: constraints) for (const auto &c: constraints)
ret << " (" << c->getSymbolicExpression() << ")"; ret << " (" << c->getSymbolicExpression() << ")";
ret << std::endl; ret << std::endl;
return ret.str(); return ret.str();
@ -1851,7 +1851,7 @@ static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
#endif #endif
} else if (!argValues.empty()) { } else if (!argValues.empty()) {
bool bailout = false; bool bailout = false;
for (const auto v: argValues) for (const auto &v: argValues)
bailout |= (v && v->type == ExprEngine::ValueType::BailoutValue); bailout |= (v && v->type == ExprEngine::ValueType::BailoutValue);
if (!bailout) if (!bailout)
data.addMissingContract(functionName); data.addMissingContract(functionName);