From 91b9854932887999344e4bddfb69cbf6d69b11c8 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 21 Apr 2020 17:06:49 +0200 Subject: [PATCH] Further tweaks to ConstString. --- src/__ConstStringCore.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/__ConstStringCore.hpp b/src/__ConstStringCore.hpp index 87c4d19..2989c19 100644 --- a/src/__ConstStringCore.hpp +++ b/src/__ConstStringCore.hpp @@ -24,6 +24,10 @@ } \ \ inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \ + inline __ConstStringCharHolder* CloneHolder() const noexcept { \ + _str->AddReference(); \ + return _str; \ + } \ \ public: \ name(const char* str, size_t size) \ @@ -32,15 +36,14 @@ name() : _str(GetEmptyString()), _length(0), _hash(Hash("")) { GetEmptyString()->AddReference(); }; \ explicit name(const char* str) : name(str, Length(str)){}; \ explicit name(const std::string& str) : name(str.c_str(), str.size()){}; \ - name(const name& other) : _str(other._str), _length(other._length), _hash(other._hash) { \ - _str->AddReference(); \ - } \ + name(const name& other) : _str(other.CloneHolder()), _length(other._length), _hash(other._hash) {} \ name& operator=(const name& other) { \ - if (_str == other._str) \ + if (_str == other._str) { \ + _str->AddReference(); \ return *this; \ + } \ _str->RemoveReference(); \ - _str = other._str; \ - _str->AddReference(); \ + _str = other.CloneHolder(); \ _length = other._length; \ _hash = other._hash; \ return *this; \