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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_test_case_registry_impl.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-08-21 17:37:35 +0200
committerMartin Hořeňovský2026-08-22 20:42:23 +0200
commit9915f7250dcfc2c7bbd9e86c83b29438df39d856 (patch)
tree7dae6bebf41141fa53505a29830adf4b397454a3 /src/catch2/internal/catch_test_case_registry_impl.cpp
parentf9dfb1031565f61bccabf7d95f91a7606eb74f45 (diff)
downloadcatch3-9915f7250dcfc2c7bbd9e86c83b29438df39d856.tar.gz
Preallocate test case vectors in TestRegistry
Preallocating to some reasonable and small number of tests avoids much of the geometric-reallocation threashing at low sizes, without taking up too much memory for tiny test binaries.
Diffstat (limited to 'src/catch2/internal/catch_test_case_registry_impl.cpp')
-rw-r--r--src/catch2/internal/catch_test_case_registry_impl.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp
index e77e7bce..d23056bc 100644
--- a/src/catch2/internal/catch_test_case_registry_impl.cpp
+++ b/src/catch2/internal/catch_test_case_registry_impl.cpp
@@ -22,6 +22,9 @@
namespace Catch {
namespace {
+ // Picked small-ish number at random
+ static size_t kInitialTestCount = 120;
+
static void enforceNoDuplicateTestCases(
std::vector<TestCaseHandle> const& tests ) {
auto testInfoCmp = []( TestCaseInfo const* lhs,
@@ -123,6 +126,15 @@ namespace Catch {
return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
}
+
+ TestRegistry::TestRegistry() {
+ // We pre-reserve some reasonable number of tests to avoid the
+ // initial geometric growth churning during test registration.
+ m_handles.reserve( kInitialTestCount );
+ m_viewed_test_infos.reserve( kInitialTestCount );
+ m_owned_test_infos.reserve( kInitialTestCount );
+ m_invokers.reserve( kInitialTestCount );
+ }
TestRegistry::~TestRegistry() = default;
void TestRegistry::registerTest(Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker) {