From e83218c2dfdf80fd53526fe389c0a3271696a106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 6 Apr 2026 22:51:55 +0200 Subject: [PATCH] Move all use of IResultCapture in AssertionHandler into the cpp file This has two advantages 1) Removing the include of `catch_interfaces_capture.hpp` from the header and potentially allowing further pruning later. 2) Providing small-but-measurable 1-2% speedup for assertions. --- src/catch2/internal/catch_assertion_handler.cpp | 5 +++++ src/catch2/internal/catch_assertion_handler.hpp | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/catch2/internal/catch_assertion_handler.cpp b/src/catch2/internal/catch_assertion_handler.cpp index 9a28e79c..a0fcfcb4 100644 --- a/src/catch2/internal/catch_assertion_handler.cpp +++ b/src/catch2/internal/catch_assertion_handler.cpp @@ -6,6 +6,7 @@ // SPDX-License-Identifier: BSL-1.0 #include +#include #include #include #include @@ -14,6 +15,10 @@ namespace Catch { + void AssertionHandler::finishIncomplete() { + m_resultCapture.handleIncomplete( m_assertionInfo ); + } + AssertionHandler::AssertionHandler ( StringRef macroName, SourceLineInfo const& lineInfo, diff --git a/src/catch2/internal/catch_assertion_handler.hpp b/src/catch2/internal/catch_assertion_handler.hpp index c71c6898..bc37469d 100644 --- a/src/catch2/internal/catch_assertion_handler.hpp +++ b/src/catch2/internal/catch_assertion_handler.hpp @@ -10,12 +10,13 @@ #include #include -#include #include namespace Catch { + class IResultCapture; + struct AssertionReaction { bool shouldDebugBreak = false; bool shouldThrow = false; @@ -28,6 +29,8 @@ namespace Catch { bool m_completed = false; IResultCapture& m_resultCapture; + void finishIncomplete(); + public: AssertionHandler ( StringRef macroName, @@ -35,9 +38,9 @@ namespace Catch { StringRef capturedExpression, ResultDisposition::Flags resultDisposition ); ~AssertionHandler() { - if ( !m_completed ) { - m_resultCapture.handleIncomplete( m_assertionInfo ); - } + // We want the common fast path inlinable, and the virtual + // dispatch in a function in single TU. + if ( !m_completed ) { finishIncomplete(); } }