Skip to content

Commit a656f10

Browse files
authored
avoid some unnecessary copies (danmar#5958)
this is mainly based on the warnings of the unfinished `performance-unnecessary-copy-on-last-use` clang-tidy check (see llvm/llvm-project#53489). it also includes some fixes spotted by review as well as some adjustments to the previous Coverity fixes
1 parent d8f8fa4 commit a656f10

17 files changed

+55
-56
lines changed

cli/cmdlineparser.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ static bool addIncludePathsToList(const std::string& fileList, std::list<std::st
9393
// cppcheck-suppress accessMoved - FP
9494
while (std::getline(files, pathName)) { // next line
9595
if (!pathName.empty()) {
96-
pathName = Path::removeQuotationMarks(pathName);
97-
pathName = Path::fromNativeSeparators(pathName);
96+
pathName = Path::removeQuotationMarks(std::move(pathName));
97+
pathName = Path::fromNativeSeparators(std::move(pathName));
9898

9999
// If path doesn't end with / or \, add it
100100
if (!endsWith(pathName, '/'))
@@ -433,8 +433,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
433433
else {
434434
path = 2 + argv[i];
435435
}
436-
path = Path::removeQuotationMarks(path);
437-
path = Path::fromNativeSeparators(path);
436+
path = Path::removeQuotationMarks(std::move(path));
437+
path = Path::fromNativeSeparators(std::move(path));
438438

439439
// If path doesn't end with / or \, add it
440440
if (!endsWith(path,'/'))
@@ -676,9 +676,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
676676
}
677677

678678
if (!path.empty()) {
679-
path = Path::removeQuotationMarks(path);
680-
path = Path::fromNativeSeparators(path);
681-
path = Path::simplifyPath(path);
679+
path = Path::removeQuotationMarks(std::move(path));
680+
path = Path::fromNativeSeparators(std::move(path));
681+
path = Path::simplifyPath(std::move(path));
682682

683683
if (Path::isDirectory(path)) {
684684
// If directory name doesn't end with / or \, add it

gui/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ void MainWindow::reAnalyzeSelected(const QStringList& files)
12821282
QDateTime saveCheckStartTime = mThread->getCheckStartTime();
12831283
mThread->check(checkSettings);
12841284
mUI->mResults->setCheckSettings(checkSettings);
1285-
mThread->setCheckStartTime(saveCheckStartTime);
1285+
mThread->setCheckStartTime(std::move(saveCheckStartTime));
12861286
}
12871287

12881288
void MainWindow::reAnalyze(bool all)

gui/projectfiledialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
485485
codingStandards << CODING_STANDARD_MISRA_CPP_2008;
486486
if (mUI->mAutosar->isChecked())
487487
codingStandards << CODING_STANDARD_AUTOSAR;
488-
projectFile->setCodingStandards(codingStandards);
488+
projectFile->setCodingStandards(std::move(codingStandards));
489489
projectFile->setCertIntPrecision(mUI->mEditCertIntPrecision->text().toInt());
490490
projectFile->setBughunting(mUI->mBughunting->isChecked());
491491
projectFile->setClangAnalyzer(mUI->mToolClangAnalyzer->isChecked());

gui/resultstree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ void ResultsTree::recheckSelectedFiles()
972972
selectedItems<<fileNameWithCheckPath;
973973
}
974974
}
975-
emit checkSelected(selectedItems);
975+
emit checkSelected(std::move(selectedItems));
976976
}
977977

978978
void ResultsTree::hideAllIdResult()

lib/astutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ bool isCPPCast(const Token* tok)
32253225
return tok && Token::simpleMatch(tok->previous(), "> (") && tok->astOperand2() && tok->astOperand1() && isCPPCastKeyword(tok->astOperand1());
32263226
}
32273227

3228-
bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> skipPredicate)
3228+
bool isConstVarExpression(const Token *tok, const std::function<bool(const Token*)>& skipPredicate)
32293229
{
32303230
if (!tok)
32313231
return false;
@@ -3255,7 +3255,7 @@ bool isConstVarExpression(const Token *tok, std::function<bool(const Token*)> sk
32553255
if (Token::Match(tok, "%cop%|[|.")) {
32563256
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1(), skipPredicate))
32573257
return false;
3258-
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), std::move(skipPredicate)))
3258+
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2(), skipPredicate))
32593259
return false;
32603260
return true;
32613261
}

lib/astutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ bool isLikelyStreamRead(bool cpp, const Token *op);
437437

438438
bool isCPPCast(const Token* tok);
439439

440-
bool isConstVarExpression(const Token* tok, std::function<bool(const Token*)> skipPredicate = nullptr);
440+
bool isConstVarExpression(const Token* tok, const std::function<bool(const Token*)>& skipPredicate = nullptr);
441441

442442
bool isLeafDot(const Token* tok);
443443

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static std::string arrayIndexMessage(const Token* tok,
388388
auto add_dim = [](const std::string &s, const Dimension &dim) {
389389
return s + "[" + std::to_string(dim.num) + "]";
390390
};
391-
const std::string array = std::accumulate(dimensions.cbegin(), dimensions.cend(), tok->astOperand1()->expressionString(), add_dim);
391+
const std::string array = std::accumulate(dimensions.cbegin(), dimensions.cend(), tok->astOperand1()->expressionString(), std::move(add_dim));
392392

393393
std::ostringstream errmsg;
394394
if (condition)

lib/forwardanalyzer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace {
116116
}
117117

118118
template<class T, class F, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
119-
Progress traverseTok(T* tok, F f, bool traverseUnknown, T** out = nullptr) {
119+
Progress traverseTok(T* tok, const F &f, bool traverseUnknown, T** out = nullptr) {
120120
if (Token::Match(tok, "asm|goto"))
121121
return Break(Analyzer::Terminate::Bail);
122122
if (Token::Match(tok, "setjmp|longjmp (")) {
@@ -166,7 +166,7 @@ namespace {
166166
}
167167

168168
template<class T, class F, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
169-
Progress traverseRecursive(T* tok, F f, bool traverseUnknown, unsigned int recursion=0) {
169+
Progress traverseRecursive(T* tok, const F &f, bool traverseUnknown, unsigned int recursion=0) {
170170
if (!tok)
171171
return Progress::Continue;
172172
if (recursion > 10000)

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static bool simplifyPathWithVariables(std::string &s, std::map<std::string, std:
137137
}
138138
if (s.find("$(") != std::string::npos)
139139
return false;
140-
s = Path::simplifyPath(Path::fromNativeSeparators(s));
140+
s = Path::simplifyPath(Path::fromNativeSeparators(std::move(s)));
141141
return true;
142142
}
143143

lib/pathanalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ PathAnalysis::Progress PathAnalysis::forwardRange(const Token* startToken, const
8787
if (Token::Match(tok, "asm|goto|break|continue"))
8888
return Progress::Break;
8989
if (Token::Match(tok, "return|throw")) {
90-
forwardRecursive(tok, info, f);
90+
forwardRecursive(tok, std::move(info), f);
9191
return Progress::Break;
9292
// Evaluate RHS of assignment before LHS
9393
}

0 commit comments

Comments
 (0)