diff options
| author | Phil Nash | 2017-11-17 23:32:04 +0000 |
|---|---|---|
| committer | GitHub | 2017-11-17 23:32:04 +0000 |
| commit | 505d2f897748ece76f2b7364591b6b3b118e0293 (patch) | |
| tree | 02ab96789fb9e1c678f7c616ec64e5273858581c /include | |
| parent | b0c379f62122c95e7494fd6349b3804d58906793 (diff) | |
| parent | f18366150e85f057e0e06ed33c7ad181c7e57a29 (diff) | |
| download | catch3-505d2f897748ece76f2b7364591b6b3b118e0293.tar.gz | |
Merge pull request #1107 from coombez/contrib
performance improvements
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_context.cpp | 19 | ||||
| -rw-r--r-- | include/internal/catch_context.h | 21 | ||||
| -rw-r--r-- | include/internal/catch_stringref.cpp | 4 | ||||
| -rw-r--r-- | include/internal/catch_stringref.h | 9 |
4 files changed, 34 insertions, 19 deletions
diff --git a/include/internal/catch_context.cpp b/include/internal/catch_context.cpp index c917a1d4..0341a6f1 100644 --- a/include/internal/catch_context.cpp +++ b/include/internal/catch_context.cpp @@ -45,21 +45,16 @@ namespace Catch { IResultCapture* m_resultCapture = nullptr; }; - namespace { - Context* currentContext = nullptr; - } - IMutableContext& getCurrentMutableContext() { - if( !currentContext ) - currentContext = new Context(); - return *currentContext; - } - IContext& getCurrentContext() { - return getCurrentMutableContext(); + IMutableContext *IMutableContext::currentContext = nullptr; + + void IMutableContext::createContext() + { + currentContext = new Context(); } void cleanUpContext() { - delete currentContext; - currentContext = nullptr; + delete IMutableContext::currentContext; + IMutableContext::currentContext = nullptr; } IContext::~IContext() = default; IMutableContext::~IMutableContext() = default; diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h index c88236a9..eb8611cc 100644 --- a/include/internal/catch_context.h +++ b/include/internal/catch_context.h @@ -15,6 +15,7 @@ namespace Catch { struct IResultCapture; struct IRunner; struct IConfig; + struct IMutableContext; using IConfigPtr = std::shared_ptr<IConfig const>; @@ -33,10 +34,26 @@ namespace Catch { virtual void setResultCapture( IResultCapture* resultCapture ) = 0; virtual void setRunner( IRunner* runner ) = 0; virtual void setConfig( IConfigPtr const& config ) = 0; + + private: + static IMutableContext *currentContext; + friend IMutableContext& getCurrentMutableContext(); + friend void cleanUpContext(); + static void createContext(); }; - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); + inline IMutableContext& getCurrentMutableContext() + { + if( !IMutableContext::currentContext ) + IMutableContext::createContext(); + return *IMutableContext::currentContext; + } + + inline IContext& getCurrentContext() + { + return getCurrentMutableContext(); + } + void cleanUpContext(); } 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; |