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;
|
char* _value;
|
||||||
std::atomic<size_t> _references;
|
std::atomic<size_t> _references;
|
||||||
|
|
||||||
|
__ConstStringCharHolder(const __ConstStringCharHolder& o) = delete;
|
||||||
|
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
||||||
|
|
||||||
public:
|
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);
|
strncpy(_value, value, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
~__ConstStringCharHolder() { delete[] _value; }
|
~__ConstStringCharHolder() { delete[] _value; }
|
||||||
|
|
||||||
inline void RemoveReference() {
|
inline void RemoveReference() {
|
||||||
if (--_references == 0) {
|
if (--_references <= 0) {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,23 +11,19 @@
|
||||||
namespace Arbutils { \
|
namespace Arbutils { \
|
||||||
class name { \
|
class name { \
|
||||||
private: \
|
private: \
|
||||||
__ConstStringCharHolder* _str; \
|
__ConstStringCharHolder* _str = nullptr; \
|
||||||
size_t _length; \
|
size_t _length; \
|
||||||
uint32_t _hash; \
|
uint32_t _hash; \
|
||||||
|
static __ConstStringCharHolder* _emptyString; \
|
||||||
\
|
\
|
||||||
hashFunction; \
|
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; } \
|
||||||
\
|
\
|
||||||
name(const char* str, size_t size, uint32_t hash) \
|
|
||||||
: _str(new __ConstStringCharHolder(str, size)), _length(size), _hash(hash) {} \
|
|
||||||
\
|
|
||||||
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)) {} \
|
||||||
_str->AddReference(); \
|
name() : _str(_emptyString), _length(0), _hash(Hash("")) { _emptyString->AddReference(); }; \
|
||||||
} \
|
|
||||||
name() : name("", 0){}; \
|
|
||||||
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()){}; \
|
||||||
name(const name& other) : _str(other._str), _length(other._length), _hash(other._hash) { \
|
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 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()); } \
|
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 { \
|
class name##_Literal { \
|
||||||
private: \
|
private: \
|
||||||
|
|
Loading…
Reference in New Issue