Cache IResultCapture in AssertionHandler to avoid repeated lookups

This commit is contained in:
Phil Nash 2017-11-23 19:21:09 +00:00
parent 9329d97a43
commit f417995afc
2 changed files with 10 additions and 7 deletions

View File

@ -56,14 +56,15 @@ namespace Catch {
SourceLineInfo const& lineInfo, SourceLineInfo const& lineInfo,
StringRef capturedExpression, StringRef capturedExpression,
ResultDisposition::Flags resultDisposition ) 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() { AssertionHandler::~AssertionHandler() {
if ( !m_completed ) { if ( !m_completed ) {
handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" ); 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()) if(result && !getCurrentContext().getConfig()->includeSuccessfulResults())
{ {
getCurrentContext().getResultCapture()->assertionRun(); m_resultCapture.assertionRun();
getCurrentContext().getResultCapture()->assertionPassed(); m_resultCapture.assertionPassed();
return; return;
} }
@ -95,12 +96,12 @@ namespace Catch {
} }
void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) { void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) {
getResultCapture().assertionRun(); m_resultCapture.assertionRun();
AssertionResult assertionResult{ m_assertionInfo, resultData }; AssertionResult assertionResult{ m_assertionInfo, resultData };
assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
getResultCapture().assertionEnded( assertionResult ); m_resultCapture.assertionEnded( assertionResult );
if( !assertionResult.isOk() ) { if( !assertionResult.isOk() ) {
m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak(); m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak();

View File

@ -15,6 +15,7 @@ namespace Catch {
struct TestFailureException{}; struct TestFailureException{};
struct AssertionResultData; struct AssertionResultData;
struct IResultCapture;
class LazyExpression { class LazyExpression {
friend class AssertionHandler; friend class AssertionHandler;
@ -37,6 +38,7 @@ namespace Catch {
bool m_shouldDebugBreak = false; bool m_shouldDebugBreak = false;
bool m_shouldThrow = false; bool m_shouldThrow = false;
bool m_completed = false; bool m_completed = false;
IResultCapture& m_resultCapture;
public: public:
AssertionHandler AssertionHandler