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

performance improvement - StringRef::operator=

inlined and reduced data copy in half.
Further work on #1086.
Brings test from 0m44.942s to 0m37.913.
Commit
fe725648a7c288db925456ddc23cdd582f210d1b
Author
Neal Coombes ·
Parents
b0c379f62122

Files · Download .tar.gz

Changes

 include/internal/catch_stringref.cpp | 4 ----
 include/internal/catch_stringref.h   | 9 ++++++++-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index 5a15bbf6..49d9629f 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -17,10 +17,6 @@
 
 namespace Catch {
 
-    auto StringRef::operator = ( StringRef other ) noexcept -> StringRef& {
-        swap( other );
-        return *this;
-    }
     StringRef::operator std::string() const {
         return std::string( m_start, m_size );
     }
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index fabd9ce8..2a9ad4c2 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -77,7 +77,14 @@ namespace Catch {
             delete[] m_data;
         }
 
-        auto operator = ( StringRef other ) noexcept -> StringRef&;
+        auto operator = ( StringRef const &other ) noexcept -> StringRef& {
+            delete[] m_data;
+            m_data = nullptr;
+            m_start = other.m_start;
+            m_size = other.m_size;
+            return *this;
+        }
+
         operator std::string() const;
 
         void swap( StringRef& other ) noexcept;