diff options
| author | Martin Hořeňovský | 2026-09-09 22:42:22 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-09-11 11:27:24 +0200 |
| commit | ee4b6eadb7f82b4a866324a3c29637d743880bcc (patch) | |
| tree | 29f70913b4be4919c1c837a0c7a890a069158243 | |
| parent | 2f03f0079fc8c7be54265386fbc26ae2f3ff10f0 (diff) | |
| download | catch3-ee4b6eadb7f82b4a866324a3c29637d743880bcc.tar.gz | |
Inline sort + unique for <= 2 tags
| -rw-r--r-- | src/catch2/catch_test_case_info.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp index 925db045..4ccc3d52 100644 --- a/src/catch2/catch_test_case_info.cpp +++ b/src/catch2/catch_test_case_info.cpp @@ -14,6 +14,7 @@ #include <cassert> #include <cctype> #include <algorithm> +#include <utility> namespace Catch { @@ -205,10 +206,21 @@ namespace Catch { internalAppendTag("."_sr); } - // Sort and prepare tags - std::sort(begin(tags), end(tags)); - tags.erase(std::unique(begin(tags), end(tags)), - end(tags)); + // Tests usually have small number of tags, so we explicitly handle + // the 1 and 2 tags cases for better performance in low-opt builds. + switch ( tags.size() ) { + case 1: + break; + case 2: + if ( tags[0] == tags[1] ) { tags.pop_back(); } + else if ( tags[1] < tags[0] ) { std::swap( tags[0], tags[1] ); } + break; + default: + std::sort( begin( tags ), end( tags ) ); + tags.erase( std::unique( begin( tags ), end( tags ) ), + end( tags ) ); + } + } bool TestCaseInfo::isHidden() const { |