From bcb2f12daf2162569ccf615ba1bf19d8825f5a90 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 31 Jul 2023 14:35:55 +0200 Subject: [PATCH] use more appropriate container for error list --- cli/executor.cpp | 3 +-- cli/executor.h | 4 ++-- lib/cppcheck.cpp | 4 +--- lib/cppcheck.h | 3 ++- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cli/executor.cpp b/cli/executor.cpp index 07591b9be401..c30152686740 100644 --- a/cli/executor.cpp +++ b/cli/executor.cpp @@ -48,8 +48,7 @@ bool Executor::hasToLog(const ErrorMessage &msg) return false; std::lock_guard lg(mErrorListSync); - if (std::find(mErrorList.cbegin(), mErrorList.cend(), errmsg) == mErrorList.cend()) { - mErrorList.emplace_back(std::move(errmsg)); + if (mErrorList.emplace(std::move(errmsg)).second) { return true; } } diff --git a/cli/executor.h b/cli/executor.h index 73247170c0a6..2d3deef71e79 100644 --- a/cli/executor.h +++ b/cli/executor.h @@ -20,10 +20,10 @@ #define EXECUTOR_H #include -#include #include #include #include +#include class Settings; class ErrorLogger; @@ -71,7 +71,7 @@ class Executor { private: std::mutex mErrorListSync; // TODO: store hashes instead of full messages - std::list mErrorList; + std::unordered_set mErrorList; }; /// @} diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 46f8efee0a12..e6d1d5ab37ef 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1603,7 +1603,7 @@ void CppCheck::reportErr(const ErrorMessage &msg) return; // Alert only about unique errors - if (std::find(mErrorList.cbegin(), mErrorList.cend(), errmsg) != mErrorList.cend()) + if (!mErrorList.emplace(std::move(errmsg)).second) return; if (!mSettings.buildDir.empty()) @@ -1613,8 +1613,6 @@ void CppCheck::reportErr(const ErrorMessage &msg) mExitCode = 1; } - mErrorList.emplace_back(std::move(errmsg)); - mErrorLogger.reportErr(msg); // check if plistOutput should be populated and the current output file is open and the error is not suppressed if (!mSettings.plistOutput.empty() && mPlistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) { diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 5756a5745074..8dc12895f078 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -35,6 +35,7 @@ #include #include #include +#include #include class Tokenizer; @@ -208,7 +209,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger { void reportOut(const std::string &outmsg, Color c = Color::Reset) override; // TODO: store hashes instead of the full messages - std::list mErrorList; + std::unordered_set mErrorList; Settings mSettings; void reportProgress(const std::string &filename, const char stage[], const std::size_t value) override;