Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-12-27 21:43:40 +0100
committerMartin Hořeňovský2023-12-27 21:43:49 +0100
commitb52d97855d794175e69abc6f0eceee9ec3c1bd0e (patch)
tree58a39440729f19ff1f39da58286c64dc3bcdd31a /src/catch2
parenteaafd076743407e930a11297425f33c1f78220b0 (diff)
downloadcatch3-b52d97855d794175e69abc6f0eceee9ec3c1bd0e.tar.gz
Move-enable various parts of TextFlow
This removes about 200 pointless copies from printing the help message (the original motivation for the change), and also nicely improves performance of the various reporters that depend on TextFlow.
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/internal/catch_clara.cpp4
-rw-r--r--src/catch2/internal/catch_textflow.cpp33
-rw-r--r--src/catch2/internal/catch_textflow.hpp36
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp3
4 files changed, 54 insertions, 22 deletions
diff --git a/src/catch2/internal/catch_clara.cpp b/src/catch2/internal/catch_clara.cpp
index 5f486764..c76089ee 100644
--- a/src/catch2/internal/catch_clara.cpp
+++ b/src/catch2/internal/catch_clara.cpp
@@ -366,8 +366,8 @@ namespace Catch {
optWidth = ( std::min )( optWidth, consoleWidth / 2 );
- for ( auto const& cols : rows ) {
- auto row = TextFlow::Column( cols.left )
+ for ( auto& cols : rows ) {
+ auto row = TextFlow::Column( CATCH_MOVE(cols.left) )
.width( optWidth )
.indent( 2 ) +
TextFlow::Spacer( 4 ) +
diff --git a/src/catch2/internal/catch_textflow.cpp b/src/catch2/internal/catch_textflow.cpp
index 7eac9732..857fd2b9 100644
--- a/src/catch2/internal/catch_textflow.cpp
+++ b/src/catch2/internal/catch_textflow.cpp
@@ -233,23 +233,36 @@ namespace Catch {
return os;
}
- Columns Column::operator+( Column const& other ) {
+ Columns operator+(Column const& lhs, Column const& rhs) {
Columns cols;
- cols += *this;
- cols += other;
+ cols += lhs;
+ cols += rhs;
return cols;
}
-
- Columns& Columns::operator+=( Column const& col ) {
- m_columns.push_back( col );
- return *this;
+ Columns operator+(Column&& lhs, Column&& rhs) {
+ Columns cols;
+ cols += CATCH_MOVE( lhs );
+ cols += CATCH_MOVE( rhs );
+ return cols;
}
- Columns Columns::operator+( Column const& col ) {
- Columns combined = *this;
- combined += col;
+ Columns& operator+=(Columns& lhs, Column const& rhs) {
+ lhs.m_columns.push_back( rhs );
+ return lhs;
+ }
+ Columns& operator+=(Columns& lhs, Column&& rhs) {
+ lhs.m_columns.push_back( CATCH_MOVE(rhs) );
+ return lhs;
+ }
+ Columns operator+( Columns const& lhs, Column const& rhs ) {
+ auto combined( lhs );
+ combined += rhs;
return combined;
}
+ Columns operator+( Columns&& lhs, Column&& rhs ) {
+ lhs += CATCH_MOVE( rhs );
+ return CATCH_MOVE( lhs );
+ }
} // namespace TextFlow
} // namespace Catch
diff --git a/src/catch2/internal/catch_textflow.hpp b/src/catch2/internal/catch_textflow.hpp
index 0776ab92..a78451d5 100644
--- a/src/catch2/internal/catch_textflow.hpp
+++ b/src/catch2/internal/catch_textflow.hpp
@@ -8,8 +8,10 @@
#ifndef CATCH_TEXTFLOW_HPP_INCLUDED
#define CATCH_TEXTFLOW_HPP_INCLUDED
-#include <cassert>
#include <catch2/internal/catch_console_width.hpp>
+#include <catch2/internal/catch_move_and_forward.hpp>
+
+#include <cassert>
#include <string>
#include <vector>
@@ -37,7 +39,7 @@ namespace Catch {
public:
/**
- * Iterates "lines" in `Column` and return sthem
+ * Iterates "lines" in `Column` and returns them
*/
class const_iterator {
friend Column;
@@ -91,20 +93,35 @@ namespace Catch {
using iterator = const_iterator;
explicit Column( std::string const& text ): m_string( text ) {}
+ explicit Column( std::string&& text ):
+ m_string( CATCH_MOVE(text)) {}
- Column& width( size_t newWidth ) {
+ Column& width( size_t newWidth ) & {
assert( newWidth > 0 );
m_width = newWidth;
return *this;
}
- Column& indent( size_t newIndent ) {
+ Column&& width( size_t newWidth ) && {
+ assert( newWidth > 0 );
+ m_width = newWidth;
+ return CATCH_MOVE( *this );
+ }
+ Column& indent( size_t newIndent ) & {
m_indent = newIndent;
return *this;
}
- Column& initialIndent( size_t newIndent ) {
+ Column&& indent( size_t newIndent ) && {
+ m_indent = newIndent;
+ return CATCH_MOVE( *this );
+ }
+ Column& initialIndent( size_t newIndent ) & {
m_initialIndent = newIndent;
return *this;
}
+ Column&& initialIndent( size_t newIndent ) && {
+ m_initialIndent = newIndent;
+ return CATCH_MOVE( *this );
+ }
size_t width() const { return m_width; }
const_iterator begin() const { return const_iterator( *this ); }
@@ -113,7 +130,8 @@ namespace Catch {
friend std::ostream& operator<<( std::ostream& os,
Column const& col );
- Columns operator+( Column const& other );
+ friend Columns operator+( Column const& lhs, Column const& rhs );
+ friend Columns operator+( Column&& lhs, Column&& rhs );
};
//! Creates a column that serves as an empty space of specific width
@@ -157,8 +175,10 @@ namespace Catch {
iterator begin() const { return iterator( *this ); }
iterator end() const { return { *this, iterator::EndTag() }; }
- Columns& operator+=( Column const& col );
- Columns operator+( Column const& col );
+ friend Columns& operator+=( Columns& lhs, Column const& rhs );
+ friend Columns& operator+=( Columns& lhs, Column&& rhs );
+ friend Columns operator+( Columns const& lhs, Column const& rhs );
+ friend Columns operator+( Columns&& lhs, Column&& rhs );
friend std::ostream& operator<<( std::ostream& os,
Columns const& cols );
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index bbde5ec9..81fc656f 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -315,11 +315,10 @@ public:
*this << RowBreak();
TextFlow::Columns headerCols;
- auto spacer = TextFlow::Spacer(2);
for (auto const& info : m_columnInfos) {
assert(info.width > 2);
headerCols += TextFlow::Column(info.name).width(info.width - 2);
- headerCols += spacer;
+ headerCols += TextFlow::Spacer( 2 );
}
m_os << headerCols << '\n';