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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-01-28 13:00:24 +0100
committerMartin Hořeňovský2023-01-28 13:00:30 +0100
commit2403f5620e60b41d84e35a88bacbb8bd8e1d92a8 (patch)
treeb26a699a75f717f8dec9a8b86dbaf35556bd0956 /src/catch2/internal
parentd58491c85a534a9348634ac3e4eb384df22f4d71 (diff)
downloadcatch3-2403f5620e60b41d84e35a88bacbb8bd8e1d92a8.tar.gz
Move SectionEndInfo into sectionEnded call in SECTION's destructor
When running `./tests/SelfTest -o /dev/null`, this saves 1272 allocations (437439 -> 437167). In general, this saves multiple allocations per end of an entered `SECTION`, if the section name was too long for SSO, because `RunContext::sectionEnded` can then move the section's name further down the callstack.
Diffstat (limited to 'src/catch2/internal')
-rw-r--r--src/catch2/internal/catch_run_context.cpp19
-rw-r--r--src/catch2/internal/catch_run_context.hpp4
-rw-r--r--src/catch2/internal/catch_section.cpp9
3 files changed, 17 insertions, 15 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index eb8f1359..86f25796 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -356,7 +356,7 @@ namespace Catch {
return true;
}
- void RunContext::sectionEnded(SectionEndInfo const & endInfo) {
+ void RunContext::sectionEnded(SectionEndInfo&& endInfo) {
Counts assertions = m_totals.assertions - endInfo.prevAssertions;
bool missingAssertions = testForMissingAssertions(assertions);
@@ -365,19 +365,20 @@ namespace Catch {
m_activeSections.pop_back();
}
- m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions));
+ m_reporter->sectionEnded(SectionStats(CATCH_MOVE(endInfo.sectionInfo), assertions, endInfo.durationInSeconds, missingAssertions));
m_messages.clear();
m_messageScopes.clear();
}
- void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) {
- if (m_unfinishedSections.empty())
+ void RunContext::sectionEndedEarly(SectionEndInfo&& endInfo) {
+ if ( m_unfinishedSections.empty() ) {
m_activeSections.back()->fail();
- else
+ } else {
m_activeSections.back()->close();
+ }
m_activeSections.pop_back();
- m_unfinishedSections.push_back(endInfo);
+ m_unfinishedSections.push_back(CATCH_MOVE(endInfo));
}
void RunContext::benchmarkPreparing( StringRef name ) {
@@ -439,7 +440,7 @@ namespace Catch {
Counts assertions;
assertions.failed = 1;
- SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false);
+ SectionStats testCaseSectionStats(CATCH_MOVE(testCaseSection), assertions, 0, false);
m_reporter->sectionEnded(testCaseSectionStats);
auto const& testInfo = m_activeTestCase->getTestCaseInfo();
@@ -518,7 +519,7 @@ namespace Catch {
m_messages.clear();
m_messageScopes.clear();
- SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
+ SectionStats testCaseSectionStats(CATCH_MOVE(testCaseSection), assertions, duration, missingAssertions);
m_reporter->sectionEnded(testCaseSectionStats);
}
@@ -542,7 +543,7 @@ namespace Catch {
itEnd = m_unfinishedSections.rend();
it != itEnd;
++it)
- sectionEnded(*it);
+ sectionEnded(CATCH_MOVE(*it));
m_unfinishedSections.clear();
}
diff --git a/src/catch2/internal/catch_run_context.hpp b/src/catch2/internal/catch_run_context.hpp
index 71c74ee3..87d637d8 100644
--- a/src/catch2/internal/catch_run_context.hpp
+++ b/src/catch2/internal/catch_run_context.hpp
@@ -70,8 +70,8 @@ namespace Catch {
bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
- void sectionEnded( SectionEndInfo const& endInfo ) override;
- void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
+ void sectionEnded( SectionEndInfo&& endInfo ) override;
+ void sectionEndedEarly( SectionEndInfo&& endInfo ) override;
IGeneratorTracker*
acquireGeneratorTracker( StringRef generatorName,
diff --git a/src/catch2/internal/catch_section.cpp b/src/catch2/internal/catch_section.cpp
index 63b4abd3..9d110dfa 100644
--- a/src/catch2/internal/catch_section.cpp
+++ b/src/catch2/internal/catch_section.cpp
@@ -26,10 +26,11 @@ namespace Catch {
Section::~Section() {
if( m_sectionIncluded ) {
SectionEndInfo endInfo{ CATCH_MOVE(m_info), m_assertions, m_timer.getElapsedSeconds() };
- if( uncaught_exceptions() )
- getResultCapture().sectionEndedEarly( endInfo );
- else
- getResultCapture().sectionEnded( endInfo );
+ if ( uncaught_exceptions() ) {
+ getResultCapture().sectionEndedEarly( CATCH_MOVE(endInfo) );
+ } else {
+ getResultCapture().sectionEnded( CATCH_MOVE( endInfo ) );
+ }
}
}