Tweaks and fixes for ConstString.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
7d98d5b467
commit
79384efb85
|
@ -13,15 +13,18 @@ namespace Arbutils {
|
|||
char* _value;
|
||||
std::atomic<size_t> _references;
|
||||
|
||||
__ConstStringCharHolder(const __ConstStringCharHolder& o) = delete;
|
||||
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
||||
|
||||
public:
|
||||
__ConstStringCharHolder(const char* value, size_t size) : _value(new char[size + 1]), _references(0) {
|
||||
__ConstStringCharHolder(const char* value, size_t size) : _value(new char[size + 1]), _references(1) {
|
||||
strncpy(_value, value, size + 1);
|
||||
}
|
||||
|
||||
~__ConstStringCharHolder() { delete[] _value; }
|
||||
|
||||
inline void RemoveReference() {
|
||||
if (--_references == 0) {
|
||||
if (--_references <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,23 +11,19 @@
|
|||
namespace Arbutils { \
|
||||
class name { \
|
||||
private: \
|
||||
__ConstStringCharHolder* _str; \
|
||||
__ConstStringCharHolder* _str = nullptr; \
|
||||
size_t _length; \
|
||||
uint32_t _hash; \
|
||||
static __ConstStringCharHolder* _emptyString; \
|
||||
\
|
||||
hashFunction; \
|
||||
\
|
||||
inline static int constexpr Length(const char* str) { return *str ? 1 + Length(str + 1) : 0; } \
|
||||
\
|
||||
name(const char* str, size_t size, uint32_t hash) \
|
||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(hash) {} \
|
||||
\
|
||||
public: \
|
||||
name(const char* str, size_t size) \
|
||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) { \
|
||||
_str->AddReference(); \
|
||||
} \
|
||||
name() : name("", 0){}; \
|
||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(Hash(str)) {} \
|
||||
name() : _str(_emptyString), _length(0), _hash(Hash("")) { _emptyString->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) { \
|
||||
|
@ -73,6 +69,7 @@
|
|||
inline static constexpr uint32_t GetHash(const char* val) { return Hash(val); } \
|
||||
inline static STDSTRINGCONSTEXPR uint32_t GetHash(const std::string& val) { return Hash(val.c_str()); } \
|
||||
}; \
|
||||
Arbutils::__ConstStringCharHolder* Arbutils::name::_emptyString = new __ConstStringCharHolder("", 0); \
|
||||
\
|
||||
class name##_Literal { \
|
||||
private: \
|
||||
|
|
Loading…
Reference in New Issue