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

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-09-07 23:15:04 +0200
committerMartin Hořeňovský2026-09-11 11:16:10 +0200
commitab13a28d125b50a458667e972ed56400af7ad931 (patch)
tree2d4c52a16a1ee1841d636cb683b8a9fe551ae61d /src
parented393f09c729a706fb1fa1f2aa1742e206a48b65 (diff)
downloadcatch3-ab13a28d125b50a458667e972ed56400af7ad931.tar.gz
Faster selection of tests to run
Similar to the change that removed `std::set` from the test registration path, this saves an allocation per test to run, and is faster to boot. Technically, the performance of selecting tests for multiple OR-joined filters, each of which selects many (most) tests is a bit slower, but that is not very common use case.
Diffstat (limited to 'src')
-rw-r--r--src/catch2/catch_session.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index 503da14f..78cb5a06 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -31,7 +31,6 @@
#include <cstdlib>
#include <exception>
#include <iomanip>
-#include <set>
namespace Catch {
@@ -86,21 +85,29 @@ namespace Catch {
assert( m_config->testSpec().getInvalidSpecs().empty() &&
"Invalid test specs should be handled before running tests" );
+ // Note that we are working with pointers into this vector
+ // of sorted test cases, so sorting/unique-ing the pointers
+ // keeps the user-specified order.
auto const& allTestCases = getAllTestCasesSorted(*m_config);
auto const& testSpec = m_config->testSpec();
+ m_tests.reserve( allTestCases.size() );
if ( !testSpec.hasFilters() ) {
for ( auto const& test : allTestCases ) {
if ( !test.getTestCaseInfo().isHidden() ) {
- m_tests.emplace( &test );
+ m_tests.push_back( &test );
}
}
} else {
- m_matches =
- testSpec.matchesByFilter( allTestCases, *m_config );
+ m_matches = testSpec.matchesByFilter( allTestCases, *m_config );
for ( auto const& match : m_matches ) {
- m_tests.insert( match.tests.begin(),
+ m_tests.insert( m_tests.end(),
+ match.tests.begin(),
match.tests.end() );
}
+ std::sort( m_tests.begin(), m_tests.end() );
+ m_tests.erase(
+ std::unique( m_tests.begin(), m_tests.end() ),
+ m_tests.end() );
}
m_tests = createShard(CATCH_MOVE(m_tests), m_config->shardCount(), m_config->shardIndex());
@@ -134,7 +141,7 @@ namespace Catch {
IEventListener* m_reporter;
Config const* m_config;
RunContext m_context;
- std::set<TestCaseHandle const*> m_tests;
+ std::vector<TestCaseHandle const*> m_tests;
TestSpec::Matches m_matches;
bool m_unmatchedTestSpecs = false;
};