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; \