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 { \
|
namespace Arbutils { \
|
||||||
class name { \
|
class name { \
|
||||||
private: \
|
private: \
|
||||||
__ConstStringCharHolder* _str = nullptr; \
|
__ConstStringCharHolder* _str; \
|
||||||
size_t _length; \
|
size_t _length; \
|
||||||
uint32_t _hash; \
|
uint32_t _hash; \
|
||||||
|
hashFunction; \
|
||||||
|
\
|
||||||
static __ConstStringCharHolder* __emptyString; \
|
static __ConstStringCharHolder* __emptyString; \
|
||||||
static inline __ConstStringCharHolder* GetEmptyString() { \
|
static inline __ConstStringCharHolder* GetEmptyString() { \
|
||||||
if (__emptyString == nullptr) \
|
if (__emptyString == nullptr) \
|
||||||
|
@ -21,13 +23,12 @@
|
||||||
return __emptyString; \
|
return __emptyString; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
hashFunction; \
|
|
||||||
\
|
|
||||||
inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \
|
inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
name(const char* str, size_t size) \
|
name(const char* str, size_t size) \
|
||||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
||||||
|
\
|
||||||
name() : _str(GetEmptyString()), _length(0), _hash(Hash("")) { GetEmptyString()->AddReference(); }; \
|
name() : _str(GetEmptyString()), _length(0), _hash(Hash("")) { GetEmptyString()->AddReference(); }; \
|
||||||
explicit name(const char* str) : name(str, Length(str)){}; \
|
explicit name(const char* str) : name(str, Length(str)){}; \
|
||||||
explicit name(const std::string& str) : name(str.c_str(), str.size()){}; \
|
explicit name(const std::string& str) : name(str.c_str(), str.size()){}; \
|
||||||
|
@ -35,8 +36,9 @@
|
||||||
_str->AddReference(); \
|
_str->AddReference(); \
|
||||||
} \
|
} \
|
||||||
name& operator=(const name& other) { \
|
name& operator=(const name& other) { \
|
||||||
if (_str != nullptr) \
|
if (_str == other._str) \
|
||||||
_str->RemoveReference(); \
|
return *this; \
|
||||||
|
_str->RemoveReference(); \
|
||||||
_str = other._str; \
|
_str = other._str; \
|
||||||
_str->AddReference(); \
|
_str->AddReference(); \
|
||||||
_length = other._length; \
|
_length = other._length; \
|
||||||
|
@ -44,10 +46,7 @@
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
~name() { \
|
~name() { _str->RemoveReference(); } \
|
||||||
if (_str != nullptr) \
|
|
||||||
_str->RemoveReference(); \
|
|
||||||
} \
|
|
||||||
\
|
\
|
||||||
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str->GetValue(); } \
|
[[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); } \
|
[[nodiscard]] inline std::string std_str() const { return std::string(_str->GetValue(), _length); } \
|
||||||
|
|
Loading…
Reference in New Issue