diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index fe483e347fe..50b13bc9c4c 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 result = PathMatch::match(fileName, errorFileName); + + if (mFileNameMatchCache.size() >= mFileNameMatchCacheMaxEntries) + mFileNameMatchCache.clear(); + + mFileNameMatchCache.emplace(errorFileName, result); + return result; +} + bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &errmsg) { switch (isSuppressed(errmsg)) { diff --git a/lib/suppressions.h b/lib/suppressions.h index 849c972d0a7..ef5f9c4e405 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 mFileNameMatchCacheMaxEntries = 256; + mutable std::map mFileNameMatchCache; }; /**