From f0ac0c8675862703bb1dbf2a5498a93b74b9f105 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 16 May 2020 09:34:35 +0200 Subject: [PATCH] Optimization: Remove simplecpp::TokenList as soon as cppecheck TokenList was created. This saves memory while checks are running (20% in my test case), although not peak memory --- lib/cppcheck.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a42b77756..165684366 100755 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -709,13 +709,12 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string mTokenizer.setTimerResults(&s_timerResults); try { - bool result; - // Create tokens, skip rest of iteration if failed - Timer timer("Tokenizer::createTokens", mSettings.showtime, &s_timerResults); - const simplecpp::TokenList &tokensP = preprocessor.preprocess(tokens1, mCurrentConfig, files, true); - mTokenizer.createTokens(&tokensP); - timer.stop(); + { + Timer timer("Tokenizer::createTokens", mSettings.showtime, &s_timerResults); + simplecpp::TokenList tokensP = preprocessor.preprocess(tokens1, mCurrentConfig, files, true); + mTokenizer.createTokens(&tokensP); + } hasValidConfig = true; // If only errors are printed, print filename after the check @@ -725,7 +724,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string mErrorLogger.reportOut("Checking " + fixedpath + ": " + mCurrentConfig + "..."); } - if (tokensP.empty()) + if (!mTokenizer.tokens()) continue; // skip rest of iteration if just checking configuration @@ -737,7 +736,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string // Simplify tokens into normal form, skip rest of iteration if failed Timer timer2("Tokenizer::simplifyTokens1", mSettings.showtime, &s_timerResults); - result = mTokenizer.simplifyTokens1(mCurrentConfig); + bool result = mTokenizer.simplifyTokens1(mCurrentConfig); timer2.stop(); if (!result) continue;