Repository: catchorg/Catch2
File: src/catch2/reporters/catch_reporter_helpers.cpp (C++)

Code before:
                : Colour::None;
            auto colourGuard = streamColour->guardColour( colour ).engage( out );

            out << TextFlow::Column(testCaseInfo.name).indent(2) << '\n';
            if (verbosity >= Verbosity::High) {
                out << TextFlow::Column(Catch::Detail::stringify(testCaseInfo.lineInfo)).indent(4) << '\n';
            }
            if (!testCaseInfo.tags.empty() &&
                verbosity > Verbosity::Quiet) {
                out << TextFlow::Column(testCaseInfo.tagsAsString()).indent(6) << '\n';
            }
        }

        if (isFiltered) {
            out << pluralise(tests.size(), "matching test case"_sr);
        } else {
            out << pluralise(tests.size(), "test case"_sr);
        }
        out << "\n\n" << std::flush;
    }

    namespace {
        struct SummaryColumn {
            SummaryColumn( std::string _label, Colour::Code _colour ):
                label( CATCH_MOVE( _label ) ), colour( _colour ) {}
            SummaryColumn addRow( std::uint64_t count ) {
                ReusableStringStream rss;
                rss << count;
                std::string row = rss.str();
                for ( auto& oldRow : rows ) {
                    while ( oldRow.size() < row.size() )
                        oldRow = ' ' + oldRow;
                    while ( oldRow.size() > row.size() )
                        row = ' ' + row;
                }
                rows.push_back( row );
                return *this;
            }

            std::string label;
            Colour::Code colour;
            std::vector<std::string> rows;
        };

        static void printSummaryRow( StringRef label,
                                     std::vector<SummaryColumn> const& cols,
                                     std::size_t row,
                                     std::ostream& stream,
                                     ColourImpl& colour ) {
            for ( auto col : cols ) {
                std::string const& value = col.rows[row];

Review comment (performance):
This is another big mess. I don't feel like saddling you with fixing the implementation, but from looking at it, the signature does not make sense either.

It returns a copy, but not before modifying the current state of the instance, so something like

`SummaryColumn&& addRow(std::uint64_t count) &&`

makes more sense IMO, so we do not copy all the rows every time (which makes repeated calls to `addRow` have quadratic complexity), and the `&&` qualifier means that this won't be modifying any lvalues.

Code after:
                : Colour::None;
            auto colourGuard = streamColour->guardColour( colour ).engage( out );

            out << TextFlow::Column(testCaseInfo.name).indent(2) << '\n';
            if (verbosity >= Verbosity::High) {
                out << TextFlow::Column(Catch::Detail::stringify(testCaseInfo.lineInfo)).indent(4) << '\n';
            }
            if (!testCaseInfo.tags.empty() &&
                verbosity > Verbosity::Quiet) {
                out << TextFlow::Column(testCaseInfo.tagsAsString()).indent(6) << '\n';
            }
        }

        if (isFiltered) {
            out << pluralise(tests.size(), "matching test case"_sr);
        } else {
            out << pluralise(tests.size(), "test case"_sr);
        }
        out << "\n\n" << std::flush;
    }

    namespace {
        class SummaryColumn {
        public:
            SummaryColumn( std::string suffix, Colour::Code colour ):
                m_suffix( CATCH_MOVE( suffix ) ), m_colour( colour ) {}

            SummaryColumn&& addRow( std::uint64_t count ) && {
                std::string row = std::to_string(count);
                auto const new_width = std::max( m_width, row.size() );
                if ( new_width > m_width ) {
                    for ( auto& oldRow : m_rows ) {
                        oldRow.insert( 0, new_width - m_width, ' ' );
                    }
                } else {
                    row.insert( 0, m_width - row.size(), ' ' );
                }
                m_width = new_width;
                m_rows.push_back( row );
                return std::move( *this );
            }

            std::string const& getSuffix() const { return m_suffix; }
            Colour::Code getColour() const { return m_colour; }
            std::string const& getRow( std::size_t index ) const {
                return m_rows[index];
            }

        private:
            std::string m_suffix;
            Colour::Code m_colour;