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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-09-09 22:35:31 +0200
committerMartin Hořeňovský2026-09-11 11:21:24 +0200
commit2f03f0079fc8c7be54265386fbc26ae2f3ff10f0 (patch)
treeb7cddcfb553812b05224e63160219fdd277fc636
parent5e47f48ecc68ff48c3c085d93502559038141693 (diff)
downloadcatch3-2f03f0079fc8c7be54265386fbc26ae2f3ff10f0.tar.gz
TestCaseInfo constructor reserves vector for tags
-rw-r--r--src/catch2/catch_test_case_info.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp
index d775b89a..925db045 100644
--- a/src/catch2/catch_test_case_info.cpp
+++ b/src/catch2/catch_test_case_info.cpp
@@ -134,6 +134,18 @@ namespace Catch {
auto requiredSize = originalTags.size() + sizeOfExtraTags(_lineInfo.file);
backingTags.reserve(requiredSize);
+ // Since there is usually only small number of tags on a test case,
+ // the geometric growth on vector does not get time to properly
+ // amortize the reallocations. But we can save a lot of time by
+ // pre-allocating space for all tags.
+ if ( !originalTags.empty() ) {
+ size_t tagCount = 1; // 1 for filename tag
+ for ( size_t i = 0; i < originalTags.size(); ++i ) {
+ if ( originalTags[i] == '[' ) { ++tagCount; }
+ }
+ tags.reserve( tagCount );
+ }
+
// We cannot copy the tags directly, as we need to normalize
// some tags, so that [.foo] is copied as [.][foo].
size_t tagStart = 0;