From e40d45a0c9fd748292bfe093b352e8496568d4d5 Mon Sep 17 00:00:00 2001 From: Guillaume Chauvel Date: Tue, 1 Dec 2026 11:48:47 +0100 Subject: [PATCH 1/2] Fix #15293 (Slow cached run with --cppcheck-build-dir on projects with many files) --- cli/cppcheckexecutor.cpp | 9 +++++- gui/checkthread.cpp | 2 +- gui/mainwindow.cpp | 2 ++ lib/analyzerinfo.cpp | 50 +++++++++++++++++++++++++++----- lib/analyzerinfo.h | 13 +++++++++ lib/cppcheck.cpp | 10 +++---- lib/settings.cpp | 4 ++- lib/settings.h | 8 ++++- lib/summaries.cpp | 2 +- lib/tokenize.cpp | 2 +- test/cli/other_test.py | 23 +++++++++++---- test/testanalyzerinformation.cpp | 38 ++++++++++++++++++++++++ 12 files changed, 138 insertions(+), 25 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index d590b6c48d3..12f22058540 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -277,6 +277,13 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) mFiles = parser.getFiles(); mFileSettings = parser.getFileSettings(); + if (!settings.buildDir.empty()) { + std::list fileNames; + for (auto i = mFiles.cbegin(); i != mFiles.cend(); ++i) + fileNames.emplace_back(i->path()); + settings.buildDirFilesTxt = AnalyzerInformation::getFilesTxtIndex(fileNames, mFileSettings); + } + const int ret = check_wrapper(settings, supprs); return ret; @@ -382,7 +389,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con // TODO: what if sourcefile is empty? for (const AnalyzerInfoId &id : ids) { - AnalyzerInformation analyzerInfo; + AnalyzerInformation analyzerInfo(settings.buildDirFilesTxt.get()); // FIXME: this is a horrible hack // we need to "re-open" the file so we can add the unmatchedSuppression findings. // we cannot keep it open conditionally because the whole program analysis reads the XML. diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 2b4c9ba654f..d3c61788d5d 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -253,7 +253,7 @@ void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings const std::string &buildDir = settings.buildDir; if (!buildDir.empty()) { - analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(buildDir, fileSettings->sfilename(), fileSettings->cfg, fileSettings->file.fsFileId())); + analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(settings.buildDirFilesTxt.get(), buildDir, fileSettings->sfilename(), fileSettings->cfg, fileSettings->file.fsFileId())); QStringList args2(args); args2.insert(0,"-E"); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5e40f13e6c1..b5e58a4f819 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -653,6 +653,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo checkSettings.loadSummaries(); std::list sourcefiles; AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings); + checkSettings.buildDirFilesTxt = AnalyzerInformation::getFilesTxtIndex(sourcefiles, p.fileSettings); } //mThread->SetanalyzeProject(true); @@ -731,6 +732,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c checkSettings.loadSummaries(); const auto& sourcefiles = toStdStringList>(fileNames); AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}); + checkSettings.buildDirFilesTxt = AnalyzerInformation::getFilesTxtIndex(sourcefiles, {}); } mThread->setCheckFiles(true); diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index f7fa3699a8d..533accc4fa8 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -33,6 +33,25 @@ #include "xml.h" +static AnalyzerInformation::FilesTxt readFilesTxt(std::istream& filesTxt) +{ + AnalyzerInformation::FilesTxt index; + std::string line; + while (std::getline(filesTxt, line)) { + AnalyzerInformation::Info filesTxtInfo; + if (!filesTxtInfo.parse(line)) + continue; // TODO: report error? + index.emplace(std::make_tuple(filesTxtInfo.sourceFile, filesTxtInfo.cfg, filesTxtInfo.fsFileId), filesTxtInfo.afile); + } + return index; +} + +static std::string findAfile(const AnalyzerInformation::FilesTxt& index, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId) +{ + const auto it = index.find(std::make_tuple(Path::simplifyPath(sourcefile), cfg, fsFileId)); + return it == index.end() ? "" : it->second; +} + // Not XMLDocument::LoadFile(): with MSVC it denies writing, and addons inherit the handle (#15207) static tinyxml2::XMLError loadFile(tinyxml2::XMLDocument &doc, const std::string &filename) { @@ -69,6 +88,12 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std:: fout << getFilesTxt(sourcefiles, fileSettings); } +std::shared_ptr AnalyzerInformation::getFilesTxtIndex(const std::list &sourcefiles, const std::list &fileSettings) +{ + std::istringstream istr(getFilesTxt(sourcefiles, fileSettings)); + return std::make_shared(readFilesTxt(istr)); +} + void AnalyzerInformation::writeIncludes(const std::set &files) { if (!files.empty() && mOutputStream.is_open()) { @@ -90,7 +115,7 @@ std::set AnalyzerInformation::getIncludes(const std::string &buildD if (buildDir.empty() || sourcefile.empty()) return files; - const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir, sourcefile, cfg, fsFileId); + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mFilesTxt, buildDir, sourcefile, cfg, fsFileId); tinyxml2::XMLDocument analyzerInfoDoc; if (loadFile(analyzerInfoDoc, analyzerInfoFile) != tinyxml2::XML_SUCCESS) @@ -222,12 +247,21 @@ std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& f std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId) { - std::ifstream fin(Path::join(buildDir, "files.txt")); - if (fin.is_open()) { - const std::string& ret = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfg, fsFileId); - if (!ret.empty()) - return Path::join(buildDir, ret); + return getAnalyzerInfoFile(nullptr, buildDir, sourcefile, cfg, fsFileId); +} + +std::string AnalyzerInformation::getAnalyzerInfoFile(const FilesTxt *filesTxt, const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId) +{ + std::string afile; + if (!filesTxt) { + std::ifstream fin(Path::join(buildDir, "files.txt")); + if (fin.is_open()) + afile = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfg, fsFileId); + } else { + afile = findAfile(*filesTxt, sourcefile, cfg, fsFileId); } + if (!afile.empty()) + return Path::join(buildDir, afile); const std::string::size_type pos = sourcefile.rfind('/'); std::string filename; @@ -247,7 +281,7 @@ bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::st if (buildDir.empty() || sourcefile.empty()) return true; - const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fsFileId); + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mFilesTxt, buildDir, sourcefile, cfg, fsFileId); { tinyxml2::XMLDocument analyzerInfoDoc; @@ -380,7 +414,7 @@ void AnalyzerInformation::reopen(const std::string &buildDir, const std::string if (buildDir.empty() || sourcefile.empty()) return; - const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fsFileId); + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mFilesTxt, buildDir, sourcefile, cfg, fsFileId); std::ifstream ifs(analyzerInfoFile); if (!ifs.is_open()) return; diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index 75ff519db84..1e507caae82 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -27,8 +27,11 @@ #include #include #include +#include +#include #include #include +#include class ErrorMessage; struct FileSettings; @@ -56,9 +59,16 @@ namespace tinyxml2 { */ class CPPCHECKLIB AnalyzerInformation { public: + /** afile of each source file, cfg and fsFileId of files.txt */ + using FilesTxt = std::map, std::string>; + + AnalyzerInformation() = default; + /** find the analyzer information files in filesTxt instead of reading files.txt */ + explicit AnalyzerInformation(const FilesTxt *filesTxt) : mFilesTxt(filesTxt) {} ~AnalyzerInformation(); static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings); + static std::shared_ptr getFilesTxtIndex(const std::list &sourcefiles, const std::list &fileSettings); /** Close current TU.analyzerinfo file */ void close(); @@ -72,6 +82,8 @@ class CPPCHECKLIB AnalyzerInformation { std::set getIncludes(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId) const; void writeHash(std::size_t hash); static std::string getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId); + /** files.txt is read when filesTxt is null */ + static std::string getAnalyzerInfoFile(const FilesTxt *filesTxt, const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId); void reopen(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t fsFileId); @@ -96,6 +108,7 @@ class CPPCHECKLIB AnalyzerInformation { static std::string skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors); private: + const FilesTxt *mFilesTxt = nullptr; std::ofstream mOutputStream; }; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c7ac0fb9069..42878ed88df 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -366,7 +366,7 @@ static std::string getDumpFileName(const Settings& settings, const FileWithDetai extension = "." + std::to_string(settings.pid) + extension; if (!settings.dump && !settings.buildDir.empty()) - return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, file.spath(), cfg, file.fsFileId()) + extension; + return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDirFilesTxt.get(), settings.buildDir, file.spath(), cfg, file.fsFileId()) + extension; return file.spath() + extension; } @@ -710,7 +710,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) // TODO: get language from FileWithDetails object std::string clangStderr; if (!mSettings.buildDir.empty()) - clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), "", file.fsFileId()) + ".clang-stderr"; + clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDirFilesTxt.get(), mSettings.buildDir, file.spath(), "", file.fsFileId()) + ".clang-stderr"; std::string exe = mSettings.clangExecutable; #ifdef _WIN32 @@ -996,7 +996,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str // TODO: if an exception occurs in this block it will continue in an unexpected code path if (!mSettings.buildDir.empty()) { - analyzerInformation.reset(new AnalyzerInformation); + analyzerInformation.reset(new AnalyzerInformation(mSettings.buildDirFilesTxt.get())); mLogger->setAnalyzerInfo(analyzerInformation.get()); } @@ -1092,7 +1092,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str preprocessor.setPlatformInfo(); if (!mSettings.buildDir.empty()) { - analyzerInformation.reset(new AnalyzerInformation); + analyzerInformation.reset(new AnalyzerInformation(mSettings.buildDirFilesTxt.get())); mLogger->setAnalyzerInfo(analyzerInformation.get()); } @@ -1844,7 +1844,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings) std::string line; if (!mSettings.buildDir.empty()) { - const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.sfilename(), fileSettings.cfg, fileSettings.file.fsFileId()); + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDirFilesTxt.get(), mSettings.buildDir, fileSettings.sfilename(), fileSettings.cfg, fileSettings.file.fsFileId()); std::ofstream fcmd(analyzerInfoFile + ".clang-tidy-cmd"); fcmd << istr.str(); } diff --git a/lib/settings.cpp b/lib/settings.cpp index da576f7a5c8..69c44a5c97f 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -323,7 +323,9 @@ bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck) void Settings::loadSummaries() { - Summaries::loadReturn(buildDir, summaryReturn); + std::set functions; + Summaries::loadReturn(buildDir, functions); + summaryReturn = std::make_shared>(std::move(functions)); } void Settings::setCheckLevel(CheckLevel level) diff --git a/lib/settings.h b/lib/settings.h index 52f20afb7c4..5073c5fce41 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -151,6 +153,9 @@ class CPPCHECKLIB WARN_UNUSED Settings { /** @brief --cppcheck-build-dir. Always uses / as path separator. No trailing path separator. */ std::string buildDir; + /** AnalyzerInformation::FilesTxt of buildDir, files.txt is read when it is null. Shared so that copying Settings does not copy it. */ + std::shared_ptr, std::string>> buildDirFilesTxt; + /** Is the 'configuration checking' wanted? */ bool checkConfiguration{}; @@ -590,7 +595,8 @@ class CPPCHECKLIB WARN_UNUSED Settings { return Settings::mTerminated; } - std::set summaryReturn; + /** functions that return, from the summaries of buildDir, null until loadSummaries(). Shared so that copying Settings does not copy it. */ + std::shared_ptr> summaryReturn; void loadSummaries(); diff --git a/lib/summaries.cpp b/lib/summaries.cpp index 3c21a962fae..fedb60ad8b6 100644 --- a/lib/summaries.cpp +++ b/lib/summaries.cpp @@ -91,7 +91,7 @@ std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg } if (!settings.buildDir.empty()) { - const std::string filename = getSummaryFile(AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, Path::simplifyPath(tokenizer.list.getSourceFilePath()), cfg, fsFileId)); + const std::string filename = getSummaryFile(AnalyzerInformation::getAnalyzerInfoFile(settings.buildDirFilesTxt.get(), settings.buildDir, Path::simplifyPath(tokenizer.list.getSourceFilePath()), cfg, fsFileId)); if (!filename.empty()) { std::ofstream fout(filename); fout << ostr.str(); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 72873ac2475..13485f7089e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8537,7 +8537,7 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const { std::string unknownFunc; const bool ret = mSettings.library.isScopeNoReturn(endScopeToken,&unknownFunc); - if (!unknownFunc.empty() && mSettings.summaryReturn.find(unknownFunc) != mSettings.summaryReturn.end()) { + if (!unknownFunc.empty() && mSettings.summaryReturn && mSettings.summaryReturn->count(unknownFunc) != 0) { return false; } if (unknown) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 17893df9106..6ad98663ae5 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -5196,7 +5196,7 @@ def test_redundant_file_reads(tmpdir, flags, expected): assert stderr.splitlines()[-1].strip() == f'{expected} total'.encode('utf-8') -def __test_builddir_summary(tmp_path, filename, extra_args): +def __test_builddir_summary(tmp_path, filename, extra_args, use_compdb=False): with open(tmp_path / filename, 'wt') as f: f.write('void bar(void) {}\n') with open(tmp_path / 'test.c', 'wt') as f: @@ -5213,10 +5213,17 @@ def __test_builddir_summary(tmp_path, filename, extra_args): args = [ '-q', '--template=simple', - '--cppcheck-build-dir={}'.format(build_dir), - filename, - 'test.c' - ] + extra_args + '--cppcheck-build-dir={}'.format(build_dir) + ] + if use_compdb: + compdb_file = tmp_path / 'compile_commands.json' + create_compile_commands(compdb_file, [tmp_path / filename, tmp_path / 'test.c']) + args.append('--project={}'.format(compdb_file)) + test_file = tmp_path / 'test.c' + else: + args += [filename, 'test.c'] + test_file = 'test.c' + args += extra_args exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) assert exitcode == 0, stdout @@ -5238,7 +5245,7 @@ def __test_builddir_summary(tmp_path, filename, extra_args): exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) assert exitcode == 0, stdout assert stderr.splitlines() == [ - 'test.c:5:1: error: Memory leak: p [memleak]' + '{}:5:1: error: Memory leak: p [memleak]'.format(test_file) ] @@ -5246,6 +5253,10 @@ def test_builddir_summary(tmp_path): __test_builddir_summary(tmp_path, 'bar.c', []) +def test_builddir_summary_compdb(tmp_path): + __test_builddir_summary(tmp_path, 'bar.c', [], use_compdb=True) + + def test_builddir_summary_define(tmp_path): __test_builddir_summary(tmp_path, 'bar.c', ['-DX']) diff --git a/test/testanalyzerinformation.cpp b/test/testanalyzerinformation.cpp index 8f615b27b93..0899198eced 100644 --- a/test/testanalyzerinformation.cpp +++ b/test/testanalyzerinformation.cpp @@ -45,6 +45,8 @@ class TestAnalyzerInformation : public TestFixture { void run() override { TEST_CASE(getAnalyzerInfoFileFromFilesTxt); TEST_CASE(getAnalyzerInfoFile); + TEST_CASE(writeFilesTxt); + TEST_CASE(getFilesTxtIndex); TEST_CASE(duplicateFile); TEST_CASE(filesTextDuplicateFile); TEST_CASE(parse); @@ -100,6 +102,42 @@ class TestAnalyzerInformation : public TestFixture { ASSERT_EQUALS("builddir/file1.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile("builddir", "some/path/file1.c", "", 0)); } + static std::list filesTxtFileSettings() { + std::list fileSettings; + fileSettings.emplace_back("a.c", Standards::Language::C, 10); + fileSettings.back().cfg = "Debug"; + fileSettings.emplace_back("a.c", Standards::Language::C, 10); + fileSettings.back().file.setFsFileId(1); + return fileSettings; + } + + void writeFilesTxt() const { + const std::string buildDir = "testanalyzerinfo-filestxt"; + const ScopedFile filesTxt("files.txt", "", buildDir); + + AnalyzerInformation::writeFilesTxt(buildDir, {"a.c", "src/a.c"}, filesTxtFileSettings()); + ASSERT_EQUALS(buildDir + "/a.a1", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "a.c", "", 0)); + ASSERT_EQUALS(buildDir + "/a.a2", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "./src/a.c", "", 0)); + ASSERT_EQUALS(buildDir + "/a.a3", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "a.c", "Debug", 0)); + ASSERT_EQUALS(buildDir + "/a.a4", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "a.c", "", 1)); + ASSERT_EQUALS(buildDir + "/b.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "b.c", "", 0)); + + AnalyzerInformation::writeFilesTxt(buildDir, {"src/a.c", "a.c"}, {}); + ASSERT_EQUALS(buildDir + "/a.a2", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "a.c", "", 0)); + ASSERT_EQUALS(buildDir + "/a.a1", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "src/a.c", "", 0)); + ASSERT_EQUALS(buildDir + "/a.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile(buildDir, "a.c", "Debug", 0)); + } + + void getFilesTxtIndex() const { + // there is no files.txt in builddir + const std::shared_ptr filesTxt = AnalyzerInformation::getFilesTxtIndex({"a.c", "src/a.c"}, filesTxtFileSettings()); + ASSERT_EQUALS("builddir/a.a1", AnalyzerInformation::getAnalyzerInfoFile(filesTxt.get(), "builddir", "a.c", "", 0)); + ASSERT_EQUALS("builddir/a.a2", AnalyzerInformation::getAnalyzerInfoFile(filesTxt.get(), "builddir", "./src/a.c", "", 0)); + ASSERT_EQUALS("builddir/a.a3", AnalyzerInformation::getAnalyzerInfoFile(filesTxt.get(), "builddir", "a.c", "Debug", 0)); + ASSERT_EQUALS("builddir/a.a4", AnalyzerInformation::getAnalyzerInfoFile(filesTxt.get(), "builddir", "a.c", "", 1)); + ASSERT_EQUALS("builddir/b.c.analyzerinfo", AnalyzerInformation::getAnalyzerInfoFile(filesTxt.get(), "builddir", "b.c", "", 0)); + } + void filesTextDuplicateFile() const { std::list fileSettings; fileSettings.emplace_back("a.c", Standards::Language::C, 10); From f1ed8e3a0f2e7bfe3b2e9584c97ac1ab66c2870e Mon Sep 17 00:00:00 2001 From: Guillaume Chauvel Date: Tue, 1 Dec 2026 11:48:47 +0100 Subject: [PATCH 2/2] Remove the duplicated loop over files.txt --- lib/analyzerinfo.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 533accc4fa8..a5d414a9554 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -33,16 +33,23 @@ #include "xml.h" -static AnalyzerInformation::FilesTxt readFilesTxt(std::istream& filesTxt) +static bool nextFilesTxtInfo(std::istream& filesTxt, AnalyzerInformation::Info& filesTxtInfo) { - AnalyzerInformation::FilesTxt index; std::string line; while (std::getline(filesTxt, line)) { - AnalyzerInformation::Info filesTxtInfo; - if (!filesTxtInfo.parse(line)) - continue; // TODO: report error? - index.emplace(std::make_tuple(filesTxtInfo.sourceFile, filesTxtInfo.cfg, filesTxtInfo.fsFileId), filesTxtInfo.afile); + if (filesTxtInfo.parse(line)) + return true; + // TODO: report error? } + return false; +} + +static AnalyzerInformation::FilesTxt readFilesTxt(std::istream& filesTxt) +{ + AnalyzerInformation::FilesTxt index; + AnalyzerInformation::Info filesTxtInfo; + while (nextFilesTxtInfo(filesTxt, filesTxtInfo)) + index.emplace(std::make_tuple(filesTxtInfo.sourceFile, filesTxtInfo.cfg, filesTxtInfo.fsFileId), filesTxtInfo.afile); return index; } @@ -234,11 +241,8 @@ std::string AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analy std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId) { const std::string simplifiedSourcefile = Path::simplifyPath(sourcefile); - std::string line; - while (std::getline(filesTxt,line)) { - AnalyzerInformation::Info filesTxtInfo; - if (!filesTxtInfo.parse(line)) - continue; // TODO: report error? + AnalyzerInformation::Info filesTxtInfo; + while (nextFilesTxtInfo(filesTxt, filesTxtInfo)) { if (filesTxtInfo.sourceFile == simplifiedSourcefile && filesTxtInfo.cfg == cfg && filesTxtInfo.fsFileId == fsFileId) return filesTxtInfo.afile; }