Handler for when a ConstString is assigned to an already equal ConstString.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9bd30cb9c4
commit
96995d071f
|
@ -11,9 +11,11 @@
|
|||
namespace Arbutils { \
|
||||
class name { \
|
||||
private: \
|
||||
__ConstStringCharHolder* _str = nullptr; \
|
||||
__ConstStringCharHolder* _str; \
|
||||
size_t _length; \
|
||||
uint32_t _hash; \
|
||||
hashFunction; \
|
||||
\
|
||||
static __ConstStringCharHolder* __emptyString; \
|
||||
static inline __ConstStringCharHolder* GetEmptyString() { \
|
||||
if (__emptyString == nullptr) \
|
||||
|
@ -21,13 +23,12 @@
|
|||
return __emptyString; \
|
||||
} \
|
||||
\
|
||||
hashFunction; \
|
||||
\
|
||||
inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \
|
||||
\
|
||||
public: \
|
||||
name(const char* str, size_t size) \
|
||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
||||
\
|
||||
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()){}; \
|
||||
|
@ -35,7 +36,8 @@
|
|||
_str->AddReference(); \
|
||||
} \
|
||||
name& operator=(const name& other) { \
|
||||
if (_str != nullptr) \
|
||||
if (_str == other._str) \
|
||||
return *this; \
|
||||
_str->RemoveReference(); \
|
||||
_str = other._str; \
|
||||
_str->AddReference(); \
|
||||
|
@ -44,10 +46,7 @@
|
|||
return *this; \
|
||||
} \
|
||||
\
|
||||
~name() { \
|
||||
if (_str != nullptr) \
|
||||
_str->RemoveReference(); \
|
||||
} \
|
||||
~name() { _str->RemoveReference(); } \
|
||||
\
|
||||
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str->GetValue(); } \
|
||||
[[nodiscard]] inline std::string std_str() const { return std::string(_str->GetValue(), _length); } \
|
||||
|
|
Loading…
Reference in New Issue