forked from catchorg/Catch2
Let reporters opt into fast path in RunContext::assertionStarting
The fast path allows `RunContext` to skip disabling output redirect, and notifying the reporters, turning `RunContext::notifyAssertionStarted` into a no-op. This improves the overall performance of assertion handling significantly, and also prepares ground for future changes around assertion handling and thread safety. For simple 10M assertion run, this improves the running time by ~30% in Debug build and ~40% in Release build. For backwards-compatibility reasons, the fast path is disabled by default. However, none of the first party reporters use the `assertionStarting` event, so all first party reporters are opted-in.
This commit is contained in:
@@ -172,6 +172,7 @@ namespace Catch {
|
||||
m_lastKnownLineInfo("DummyLocation", static_cast<size_t>(-1)),
|
||||
m_outputRedirect( makeOutputRedirect( m_reporter->getPreferences().shouldRedirectStdOut ) ),
|
||||
m_abortAfterXFailedAssertions( m_config->abortAfter() ),
|
||||
m_reportAssertionStarting( m_reporter->getPreferences().shouldReportAllAssertionStarts ),
|
||||
m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ),
|
||||
m_shouldDebugBreak( m_config->shouldDebugBreak() )
|
||||
{
|
||||
@@ -309,8 +310,10 @@ namespace Catch {
|
||||
}
|
||||
|
||||
void RunContext::notifyAssertionStarted( AssertionInfo const& info ) {
|
||||
auto _ = scopedDeactivate( *m_outputRedirect );
|
||||
m_reporter->assertionStarting( info );
|
||||
if (m_reportAssertionStarting) {
|
||||
auto _ = scopedDeactivate( *m_outputRedirect );
|
||||
m_reporter->assertionStarting( info );
|
||||
}
|
||||
}
|
||||
|
||||
bool RunContext::sectionStarted( StringRef sectionName,
|
||||
|
||||
@@ -159,6 +159,9 @@ namespace Catch {
|
||||
size_t m_abortAfterXFailedAssertions;
|
||||
bool m_lastAssertionPassed = false;
|
||||
bool m_shouldReportUnexpected = true;
|
||||
// Caches whether `assertionStarting` events should be sent to the reporter.
|
||||
bool m_reportAssertionStarting;
|
||||
// Caches whether `assertionEnded` events for successful assertions should be sent to the reporter
|
||||
bool m_includeSuccessfulResults;
|
||||
// Caches m_config->shouldDebugBreak() to avoid vptr calls/allow inlining
|
||||
bool m_shouldDebugBreak;
|
||||
|
||||
Reference in New Issue
Block a user