From f417995afcac9c7a9af436bcb303f9fabb80d32b Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 23 Nov 2017 19:21:09 +0000 Subject: [PATCH] Cache IResultCapture in AssertionHandler to avoid repeated lookups --- include/internal/catch_assertionhandler.cpp | 15 ++++++++------- include/internal/catch_assertionhandler.h | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp index 0fe8e3e9..34540e94 100644 --- a/include/internal/catch_assertionhandler.cpp +++ b/include/internal/catch_assertionhandler.cpp @@ -56,14 +56,15 @@ namespace Catch { SourceLineInfo const& lineInfo, StringRef capturedExpression, ResultDisposition::Flags resultDisposition ) - : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition } + : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, + m_resultCapture( getResultCapture() ) { - getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo ); + m_resultCapture.assertionStarting( m_assertionInfo ); } AssertionHandler::~AssertionHandler() { if ( !m_completed ) { handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" ); - getCurrentContext().getResultCapture()->exceptionEarlyReported(); + m_resultCapture.exceptionEarlyReported(); } } @@ -74,8 +75,8 @@ namespace Catch { if(result && !getCurrentContext().getConfig()->includeSuccessfulResults()) { - getCurrentContext().getResultCapture()->assertionRun(); - getCurrentContext().getResultCapture()->assertionPassed(); + m_resultCapture.assertionRun(); + m_resultCapture.assertionPassed(); return; } @@ -95,12 +96,12 @@ namespace Catch { } void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) { - getResultCapture().assertionRun(); + m_resultCapture.assertionRun(); AssertionResult assertionResult{ m_assertionInfo, resultData }; assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; - getResultCapture().assertionEnded( assertionResult ); + m_resultCapture.assertionEnded( assertionResult ); if( !assertionResult.isOk() ) { m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak(); diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h index fb936506..02d89221 100644 --- a/include/internal/catch_assertionhandler.h +++ b/include/internal/catch_assertionhandler.h @@ -15,6 +15,7 @@ namespace Catch { struct TestFailureException{}; struct AssertionResultData; + struct IResultCapture; class LazyExpression { friend class AssertionHandler; @@ -37,6 +38,7 @@ namespace Catch { bool m_shouldDebugBreak = false; bool m_shouldThrow = false; bool m_completed = false; + IResultCapture& m_resultCapture; public: AssertionHandler