Refactor implementation of case-insensitivity in tags

By not materializing the lower cased tags ahead of time, we
save allocations at the cost of worsened performance when comparing
two tags.

Since there are rarely many tags, and commonly they are not
compared even if present, this is almost always a win. The new
implementation also improves the robustness of the code
responsible for handling tags in a case-insensitive manner.
This commit is contained in:
Martin Hořeňovský
2021-12-28 00:20:55 +01:00
parent cbb6764fb1
commit 45577a1f4c
10 changed files with 43 additions and 44 deletions
+4 -6
View File
@@ -38,15 +38,13 @@ namespace Catch {
TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
: Pattern( filterString )
, m_tag( toLower( tag ) )
, m_tag( tag )
{}
bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
return std::find_if(begin(testCase.tags),
end(testCase.tags),
[&](Tag const& tag) {
return tag.lowerCased == m_tag;
}) != end(testCase.tags);
return std::find( begin( testCase.tags ),
end( testCase.tags ),
Tag( m_tag ) ) != end( testCase.tags );
}
bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {