optimized suppression lookups a bit when no suppressions exist (#4839)

This commit is contained in:
Oliver Stöneberg 2023-03-03 18:37:09 +01:00 committed by GitHub
parent 5af6ca6637
commit 0ec2d84f1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 6 deletions

View File

@ -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);
}

View File

@ -95,7 +95,7 @@ private:
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

View File

@ -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);
}

View File

@ -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");

View File

@ -34,6 +34,7 @@
/// @{
class Tokenizer;
class ErrorMessage;
/** @brief class for handling suppressions */
class CPPCHECKLIB Suppressions {
@ -178,6 +179,13 @@ public:
*/
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

View File

@ -63,7 +63,7 @@ public:
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: