From dc1e6315ee28d864eee2adb67829b4c3b23595d6 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 2 Mar 2023 02:37:51 +0100 Subject: [PATCH] optimized suppression lookups a bit when no suppressions exist --- cli/processexecutor.cpp | 4 ++-- cli/threadexecutor.cpp | 2 +- lib/cppcheck.cpp | 4 ++-- lib/suppressions.cpp | 7 +++++++ lib/suppressions.h | 8 ++++++++ test/helpers.h | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 2aaacdd010b..b8bc5571068 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -169,7 +169,7 @@ int ProcessExecutor::handleRead(int rpipe, unsigned int &result) std::exit(EXIT_FAILURE); } - if (!mSettings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) { + if (!mSettings.nomsg.isSuppressed(msg)) { // Alert only about unique errors std::string errmsg = msg.toString(mSettings.verbose); if (std::find(mErrorList.cbegin(), mErrorList.cend(), errmsg) == mErrorList.cend()) { @@ -376,7 +376,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const "cppcheckError", Certainty::normal); - if (!mSettings.nomsg.isSuppressed(errmsg.toSuppressionsErrorMessage())) + if (!mSettings.nomsg.isSuppressed(errmsg)) mErrorLogger.reportErr(errmsg); } diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 7a0e595735a..f49110b4e6d 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -95,7 +95,7 @@ class ThreadExecutor::SyncLogForwarder : public ErrorLogger void report(const ErrorMessage &msg, MessageType msgType) { - if (mThreadExecutor.mSettings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) + if (mThreadExecutor.mSettings.nomsg.isSuppressed(msg)) return; // Alert only about unique errors diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index cdb14f1d130..0e166b0c556 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1615,6 +1615,7 @@ void CppCheck::reportErr(const ErrorMessage &msg) if (!mSettings.buildDir.empty()) mAnalyzerInformation.reportErr(msg); + // TODO: only convert if necessary const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage(); if (mUseGlobalSuppressions) { @@ -1653,8 +1654,7 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c void CppCheck::reportInfo(const ErrorMessage &msg) { - const Suppressions::ErrorMessage &errorMessage = msg.toSuppressionsErrorMessage(); - if (!mSettings.nomsg.isSuppressed(errorMessage)) + if (!mSettings.nomsg.isSuppressed(msg)) mErrorLogger.reportInfo(msg); } diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 3d6dd876dc5..fcde8f5e7bd 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -379,6 +379,13 @@ bool Suppressions::isSuppressed(const Suppressions::ErrorMessage &errmsg) return false; } +bool Suppressions::isSuppressed(const ::ErrorMessage &errmsg) +{ + if (mSuppressions.empty()) + return false; + return isSuppressed(errmsg.toSuppressionsErrorMessage()); +} + bool Suppressions::isSuppressedLocal(const Suppressions::ErrorMessage &errmsg) { const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression"); diff --git a/lib/suppressions.h b/lib/suppressions.h index 0ad827d1b61..4fd7c50ff91 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -34,6 +34,7 @@ /// @{ class Tokenizer; +class ErrorMessage; /** @brief class for handling suppressions */ class CPPCHECKLIB Suppressions { @@ -178,6 +179,13 @@ class CPPCHECKLIB Suppressions { */ bool isSuppressed(const ErrorMessage &errmsg); + /** + * @brief Returns true if this message should not be shown to the user. + * @param errmsg error message + * @return true if this error is suppressed. + */ + bool isSuppressed(const ::ErrorMessage &errmsg); + /** * @brief Returns true if this message should not be shown to the user, only uses local suppressions. * @param errmsg error message diff --git a/test/helpers.h b/test/helpers.h index 93974d386dd..b90e096bd1b 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -63,7 +63,7 @@ class SimpleSuppressor : public ErrorLogger { next->reportOut(outmsg); } void reportErr(const ErrorMessage &msg) override { - if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) + if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg)) next->reportErr(msg); } private: