Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() >= mFileNameMatchCacheMaxEntries)
mFileNameMatchCache.clear();

mFileNameMatchCache.emplace(errorFileName, isMatch);
return isMatch;
}

bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &errmsg)
{
switch (isSuppressed(errmsg)) {
Expand Down
6 changes: 6 additions & 0 deletions lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, bool> mFileNameMatchCache;
};

/**
Expand Down
Loading