Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-09-09 22:42:22 +0200
committerMartin Hořeňovský2026-09-11 11:27:24 +0200
commitee4b6eadb7f82b4a866324a3c29637d743880bcc (patch)
tree29f70913b4be4919c1c837a0c7a890a069158243 /src/catch2
parent2f03f0079fc8c7be54265386fbc26ae2f3ff10f0 (diff)
downloadcatch3-ee4b6eadb7f82b4a866324a3c29637d743880bcc.tar.gz
Inline sort + unique for <= 2 tags
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_test_case_info.cpp20
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 {