From 804926cb1d7e59a461386d1eb21dd8cd7dd5f0dc Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Mon, 22 Jun 2026 22:26:48 +0200 Subject: [PATCH 1/2] Improve performance of SuppressionsList::isSuppressed by returning as soon as a match is found. The same is done in the other overloads of the function. By returning immediately when a match is found, heavily improve the performance of CppCheck::CppCheckLogger reportErr function in cases where a lot of errors are being suppressed. --- lib/suppressions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index fe483e347fe..02a489f2442 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -475,16 +475,16 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, // TODO: handle unmatchedPolyspaceSuppression? const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression"); - bool returnValue = false; + for (Suppression &s : mSuppressions) { if (!global && !s.isLocal()) continue; if (unmatchedSuppression && s.errorId != errmsg.errorId) continue; if (s.isMatch(errmsg)) - returnValue = true; + return true; } - return returnValue; + return false; } bool SuppressionList::isSuppressedExplicitly(const SuppressionList::ErrorMessage &errmsg, bool global) From 35d487dccf85a11054bfd94150099b7e984ea6c3 Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Tue, 23 Jun 2026 09:58:17 +0200 Subject: [PATCH 2/2] Fix issue introduced in 804926cb1d7e59a461386d1eb21dd8cd7dd5f0dc with regards to "unmatchedSuppression". Instead of returning immediately just avoid calling isMatch when a match is already found and the suppression being checked has previously been matched. --- lib/suppressions.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 02a489f2442..ffbbe1f1a7d 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -475,16 +475,18 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, // TODO: handle unmatchedPolyspaceSuppression? const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression"); - + bool returnValue = false; for (Suppression &s : mSuppressions) { if (!global && !s.isLocal()) continue; if (unmatchedSuppression && s.errorId != errmsg.errorId) continue; + if (returnValue && s.matched) + continue; if (s.isMatch(errmsg)) - return true; + returnValue = true; } - return false; + return returnValue; } bool SuppressionList::isSuppressedExplicitly(const SuppressionList::ErrorMessage &errmsg, bool global)