Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Refactor serializeFilters implementation

Commit
360b82620ef10c1b70d809fa8593e3647220e021
Author
Martin Hořeňovský ·
Parents
2a8e317cfbe9

Files · Download .tar.gz

Changes

 .../reporters/catch_reporter_combined_tu.cpp       | 31 ++++++++++++++--------
 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;