From c57e349d1d62fcdf96aef576a5c200ae2078daad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 26 Dec 2023 11:55:19 +0100 Subject: [PATCH] Avoid copying Clara::Parser for every inserted Opt This prevents the full construction from being O(N^2) in number of `Opt`s, and also reduces the number of allocations for running no tests significantly: `tests/SelfTest`: 7705 -> 6095 `tests/ExtraTests/NoTests` 2215 -> 605 --- src/catch2/internal/catch_clara.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp index 8f6a4e9e..a9413810 100644 --- a/src/catch2/internal/catch_clara.hpp +++ b/src/catch2/internal/catch_clara.hpp @@ -636,8 +636,14 @@ namespace Catch { Parser& operator|=(Parser const& other); template - auto operator|(T const& other) const -> Parser { - return Parser(*this) |= other; + friend Parser operator|(Parser const& p, T const& rhs) { + return Parser( p ) |= rhs; + } + + template + friend Parser operator|( Parser&& p, T const& rhs ) { + p |= rhs; + return CATCH_MOVE(p); } std::vector getHelpColumns() const;