diff options
| author | Martin Hořeňovský | 2023-01-28 00:35:40 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-01-29 10:44:20 +0100 |
| commit | 65ffee518944372b35a885aa521ac28406f8b8fb (patch) | |
| tree | f2d8fb8db2bbdc03de542f99329c610c5c0224d3 /src/catch2/internal/catch_section.cpp | |
| parent | 43f02027e47310e200f20f5c3a1de6fe281e2f81 (diff) | |
| download | catch3-65ffee518944372b35a885aa521ac28406f8b8fb.tar.gz | |
Don't take ownership of SECTION's name for inactive sections
This eliminates 1945 (432709 -> 430764) allocations from running
`./tests/SelfTest -o /dev/null`. In general terms, this saves
an allocation every time an unvisited `SECTION` is passed, which
means that the saved allocations are quadratic in number of sibling
(same level) `SECTION`s in a test case.
Diffstat (limited to 'src/catch2/internal/catch_section.cpp')
| -rw-r--r-- | src/catch2/internal/catch_section.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/catch2/internal/catch_section.cpp b/src/catch2/internal/catch_section.cpp index 9d110dfa..ab9284c7 100644 --- a/src/catch2/internal/catch_section.cpp +++ b/src/catch2/internal/catch_section.cpp @@ -15,7 +15,7 @@ namespace Catch { Section::Section( SectionInfo&& info ): m_info( CATCH_MOVE( info ) ), m_sectionIncluded( - getResultCapture().sectionStarted( m_info, m_assertions ) ) { + getResultCapture().sectionStarted( m_info.name, m_info.lineInfo, m_assertions ) ) { // Non-"included" sections will not use the timing information // anyway, so don't bother with the potential syscall. if (m_sectionIncluded) { @@ -23,6 +23,23 @@ namespace Catch { } } + Section::Section( SourceLineInfo const& _lineInfo, + StringRef _name, + const char* const ): + m_info( { "invalid", static_cast<std::size_t>(-1) }, "" ), + m_sectionIncluded( + getResultCapture().sectionStarted( _name, _lineInfo, m_assertions ) ) { + // We delay initialization the SectionInfo member until we know + // this section needs it, so we avoid allocating std::string for name. + // We also delay timer start to avoid the potential syscall unless we + // will actually use the result. + if ( m_sectionIncluded ) { + m_info.name = static_cast<std::string>( _name ); + m_info.lineInfo = _lineInfo; + m_timer.start(); + } + } + Section::~Section() { if( m_sectionIncluded ) { SectionEndInfo endInfo{ CATCH_MOVE(m_info), m_assertions, m_timer.getElapsedSeconds() }; |