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

This commit is contained in:
PKEuS 2020-05-16 09:34:35 +02:00
parent ade253a730
commit f0ac0c8675
1 changed files with 7 additions and 8 deletions

View File

@ -709,13 +709,12 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
mTokenizer.setTimerResults(&s_timerResults); mTokenizer.setTimerResults(&s_timerResults);
try { try {
bool result;
// Create tokens, skip rest of iteration if failed // 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); Timer timer("Tokenizer::createTokens", mSettings.showtime, &s_timerResults);
mTokenizer.createTokens(&tokensP); simplecpp::TokenList tokensP = preprocessor.preprocess(tokens1, mCurrentConfig, files, true);
timer.stop(); mTokenizer.createTokens(&tokensP);
}
hasValidConfig = true; hasValidConfig = true;
// If only errors are printed, print filename after the check // 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 + "..."); mErrorLogger.reportOut("Checking " + fixedpath + ": " + mCurrentConfig + "...");
} }
if (tokensP.empty()) if (!mTokenizer.tokens())
continue; continue;
// skip rest of iteration if just checking configuration // 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 // Simplify tokens into normal form, skip rest of iteration if failed
Timer timer2("Tokenizer::simplifyTokens1", mSettings.showtime, &s_timerResults); Timer timer2("Tokenizer::simplifyTokens1", mSettings.showtime, &s_timerResults);
result = mTokenizer.simplifyTokens1(mCurrentConfig); bool result = mTokenizer.simplifyTokens1(mCurrentConfig);
timer2.stop(); timer2.stop();
if (!result) if (!result)
continue; continue;