Skip to content

Commit

Permalink
CppCheck: reduced lifetime of some variables / avoid some unnecessary…
Browse files Browse the repository at this point in the history
… copies
  • Loading branch information
firewave committed Mar 18, 2024
1 parent b98b3f6 commit f57353b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace {

static std::string cmdFileName(std::string f)
{
f = Path::toNativeSeparators(f);
f = Path::toNativeSeparators(std::move(f));
if (f.find(' ') != std::string::npos)
return "\"" + f + "\"";
return f;
Expand Down Expand Up @@ -623,16 +623,14 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string

mExitCode = 0;

FilesDeleter filesDeleter;

if (Settings::terminated())
return mExitCode;

const Timer fileTotalTimer(mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL, filename);

if (!mSettings.quiet) {
std::string fixedpath = Path::simplifyPath(filename);
fixedpath = Path::toNativeSeparators(fixedpath);
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
mErrorLogger.reportOut(std::string("Checking ") + fixedpath + ' ' + cfgname + std::string("..."), Color::FgGreen);

if (mSettings.verbose) {
Expand Down Expand Up @@ -675,9 +673,6 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
return EXIT_SUCCESS;
}

Preprocessor preprocessor(mSettings, this);
std::set<std::string> configurations;

simplecpp::OutputList outputList;
std::vector<std::string> files;
simplecpp::TokenList tokens1 = createTokenList(filename, files, &outputList, fileStream);
Expand Down Expand Up @@ -705,6 +700,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
return mExitCode;
}

Preprocessor preprocessor(mSettings, this);

if (!preprocessor.loadFiles(tokens1, files))
return mExitCode;

Expand Down Expand Up @@ -788,6 +785,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
}
}

FilesDeleter filesDeleter;

// write dump file xml prolog
std::ofstream fdump;
std::string dumpFile;
Expand All @@ -805,6 +804,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
preprocessor.setPlatformInfo(&tokens1);

// Get configurations..
std::set<std::string> configurations;
if ((mSettings.checkAllConfigurations && mSettings.userDefines.empty()) || mSettings.force) {
Timer t("Preprocessor::getConfigs", mSettings.showtime, &s_timerResults);
configurations = preprocessor.getConfigs(tokens1);
Expand Down Expand Up @@ -915,7 +915,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
// If only errors are printed, print filename after the check
if (!mSettings.quiet && (!mCurrentConfig.empty() || checkCount > 1)) {
std::string fixedpath = Path::simplifyPath(filename);
fixedpath = Path::toNativeSeparators(fixedpath);
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
mErrorLogger.reportOut("Checking " + fixedpath + ": " + mCurrentConfig + "...", Color::FgGreen);
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
std::string fixedpath = Path::simplifyPath(line.substr(0, endNamePos));
const int64_t lineNumber = strToInt<int64_t>(lineNumString);
const int64_t column = strToInt<int64_t>(columnNumString);
fixedpath = Path::toNativeSeparators(fixedpath);
fixedpath = Path::toNativeSeparators(std::move(fixedpath));

ErrorMessage errmsg;
errmsg.callStack.emplace_back(fixedpath, lineNumber, column);
Expand Down

0 comments on commit f57353b

Please sign in to comment.