diff options
| author | Martin Hořeňovský | 2020-08-24 10:15:47 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-08-24 10:19:26 +0200 |
| commit | 360b82620ef10c1b70d809fa8593e3647220e021 (patch) | |
| tree | 65ffd3cc07c9ed3f147d1cc5de46bc21fa648727 | |
| parent | 2a8e317cfbe92f9c108960d8d33e6cefe2c40c69 (diff) | |
| download | catch3-360b82620ef10c1b70d809fa8593e3647220e021.tar.gz | |
Refactor serializeFilters implementation
| -rw-r--r-- | src/catch2/reporters/catch_reporter_combined_tu.cpp | 31 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_helpers.hpp | 2 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp index f6a650eb..b0e1f10f 100644 --- a/src/catch2/reporters/catch_reporter_combined_tu.cpp +++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp @@ -10,13 +10,14 @@ * of Catch2 has its own combined TU like this. */ +#include <catch2/reporters/catch_reporter_helpers.hpp> #include <catch2/interfaces/catch_interfaces_config.hpp> #include <catch2/internal/catch_console_width.hpp> #include <catch2/internal/catch_errno_guard.hpp> -#include <catch2/internal/catch_stream.hpp> -#include <catch2/reporters/catch_reporter_helpers.hpp> + #include <cfloat> #include <cstdio> +#include <ostream> namespace Catch { @@ -52,18 +53,26 @@ namespace Catch { return min >= 0 && duration >= min; } - std::string serializeFilters( std::vector<std::string> const& container ) { - ReusableStringStream oss; + std::string serializeFilters( std::vector<std::string> const& filters ) { + // We add a ' ' separator between each filter + size_t serialized_size = filters.size() - 1; + for (auto const& filter : filters) { + serialized_size += filter.size(); + } + + std::string serialized; + serialized.reserve(serialized_size); bool first = true; - for ( auto&& filter : container ) { - if ( !first ) - oss << ' '; - else - first = false; - oss << filter; + for (auto const& filter : filters) { + if (!first) { + serialized.push_back(' '); + } + first = false; + serialized.append(filter); } - return oss.str(); + + return serialized; } std::ostream& operator<<( std::ostream& out, lineOfChars value ) { diff --git a/src/catch2/reporters/catch_reporter_helpers.hpp b/src/catch2/reporters/catch_reporter_helpers.hpp index 96fd51d3..88e7636b 100644 --- a/src/catch2/reporters/catch_reporter_helpers.hpp +++ b/src/catch2/reporters/catch_reporter_helpers.hpp @@ -15,7 +15,7 @@ namespace Catch { //! Should the reporter show bool shouldShowDuration( IConfig const& config, double duration ); - std::string serializeFilters( std::vector<std::string> const& container ); + std::string serializeFilters( std::vector<std::string> const& filters ); struct lineOfChars { char c; |