From fe725648a7c288db925456ddc23cdd582f210d1b Mon Sep 17 00:00:00 2001 From: Neal Coombes Date: Fri, 17 Nov 2017 14:15:26 -0600 Subject: [PATCH] performance improvement - StringRef::operator= inlined and reduced data copy in half. Further work on #1086. Brings test from 0m44.942s to 0m37.913. --- 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;