From f45c7cbc7c721fe09aa95850011e82a433a94641 Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Wed, 1 Jul 2026 17:57:01 +0200 Subject: [PATCH 1/3] Suppression file name cache. Implement a file name cache per suppression to avoid calling PathMatch::match again and again for the same suppression and file name combination. --- lib/suppressions.cpp | 17 ++++++++++++++++- lib/suppressions.h | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index fe483e347fe..10b17ec8995 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -420,7 +420,7 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed( if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber) return Result::None; } - if (!fileName.empty() && !PathMatch::match(fileName, errmsg.getFileName())) + if (!fileName.empty() && !isFileNameMatch(errmsg.getFileName())) return Result::None; if (hash > 0 && hash != errmsg.hash) return Result::Checked; @@ -453,6 +453,21 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed( return Result::Matched; } +bool SuppressionList::Suppression::isFileNameMatch(const std::string &errorFileName) const +{ + const auto it = mFileNameMatchCache.find(errorFileName); + if (it != mFileNameMatchCache.end()) + return it->second; + + const bool isMatch = PathMatch::match(fileName, errorFileName); + + if (mFileNameMatchCache.size() >= FileNameMatchCacheMaxEntries) + mFileNameMatchCache.clear(); + + mFileNameMatchCache.emplace(errorFileName, isMatch); + return isMatch; +} + bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &errmsg) { switch (isSuppressed(errmsg)) { diff --git a/lib/suppressions.h b/lib/suppressions.h index 849c972d0a7..dbd9bb2af87 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -168,6 +168,12 @@ class CPPCHECKLIB SuppressionList { bool isPolyspace{}; enum : std::int8_t { NO_LINE = -1 }; + + private: + bool isFileNameMatch(const std::string &errorFileName) const; + + static constexpr std::size_t FileNameMatchCacheMaxEntries = 256; + mutable std::map mFileNameMatchCache; }; /** From 1e97436bdf0a5756f1460abc1c3c28bc52bcde39 Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Wed, 1 Jul 2026 21:24:51 +0200 Subject: [PATCH 2/3] Fix naming violation of private member variable. --- lib/suppressions.cpp | 2 +- lib/suppressions.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 10b17ec8995..76768457ad5 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -461,7 +461,7 @@ bool SuppressionList::Suppression::isFileNameMatch(const std::string &errorFileN const bool isMatch = PathMatch::match(fileName, errorFileName); - if (mFileNameMatchCache.size() >= FileNameMatchCacheMaxEntries) + if (mFileNameMatchCache.size() >= mFileNameMatchCacheMaxEntries) mFileNameMatchCache.clear(); mFileNameMatchCache.emplace(errorFileName, isMatch); diff --git a/lib/suppressions.h b/lib/suppressions.h index dbd9bb2af87..ef5f9c4e405 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -172,7 +172,7 @@ class CPPCHECKLIB SuppressionList { private: bool isFileNameMatch(const std::string &errorFileName) const; - static constexpr std::size_t FileNameMatchCacheMaxEntries = 256; + static constexpr std::size_t mFileNameMatchCacheMaxEntries = 256; mutable std::map mFileNameMatchCache; }; From 3693c19bab0e7dab274d99e2d345fd8fea4764f5 Mon Sep 17 00:00:00 2001 From: Martin Boye Petersen Date: Thu, 2 Jul 2026 00:52:28 +0200 Subject: [PATCH 3/3] Rename local variable to avoid conflict with function name [shadowFunction]. --- lib/suppressions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 76768457ad5..50b13bc9c4c 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -459,13 +459,13 @@ bool SuppressionList::Suppression::isFileNameMatch(const std::string &errorFileN if (it != mFileNameMatchCache.end()) return it->second; - const bool isMatch = PathMatch::match(fileName, errorFileName); + const bool result = PathMatch::match(fileName, errorFileName); if (mFileNameMatchCache.size() >= mFileNameMatchCacheMaxEntries) mFileNameMatchCache.clear(); - mFileNameMatchCache.emplace(errorFileName, isMatch); - return isMatch; + mFileNameMatchCache.emplace(errorFileName, result); + return result; } bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &errmsg)