Skip to content

Commit f45c7cb

Browse files
committed
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.
1 parent 186a7a9 commit f45c7cb

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/suppressions.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(
420420
if (!thisAndNextLine || lineNumber + 1 != errmsg.lineNumber)
421421
return Result::None;
422422
}
423-
if (!fileName.empty() && !PathMatch::match(fileName, errmsg.getFileName()))
423+
if (!fileName.empty() && !isFileNameMatch(errmsg.getFileName()))
424424
return Result::None;
425425
if (hash > 0 && hash != errmsg.hash)
426426
return Result::Checked;
@@ -453,6 +453,21 @@ SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(
453453
return Result::Matched;
454454
}
455455

456+
bool SuppressionList::Suppression::isFileNameMatch(const std::string &errorFileName) const
457+
{
458+
const auto it = mFileNameMatchCache.find(errorFileName);
459+
if (it != mFileNameMatchCache.end())
460+
return it->second;
461+
462+
const bool isMatch = PathMatch::match(fileName, errorFileName);
463+
464+
if (mFileNameMatchCache.size() >= FileNameMatchCacheMaxEntries)
465+
mFileNameMatchCache.clear();
466+
467+
mFileNameMatchCache.emplace(errorFileName, isMatch);
468+
return isMatch;
469+
}
470+
456471
bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &errmsg)
457472
{
458473
switch (isSuppressed(errmsg)) {

lib/suppressions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ class CPPCHECKLIB SuppressionList {
168168
bool isPolyspace{};
169169

170170
enum : std::int8_t { NO_LINE = -1 };
171+
172+
private:
173+
bool isFileNameMatch(const std::string &errorFileName) const;
174+
175+
static constexpr std::size_t FileNameMatchCacheMaxEntries = 256;
176+
mutable std::map<std::string, bool> mFileNameMatchCache;
171177
};
172178

173179
/**

0 commit comments

Comments
 (0)