Tweaks for StringView to make the backing value the owner of the string.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
544c541bc3
commit
f64224131b
|
@ -16,22 +16,28 @@
|
||||||
|
|
||||||
namespace ArbUt {
|
namespace ArbUt {
|
||||||
class __ConstStringCharHolder {
|
class __ConstStringCharHolder {
|
||||||
std::string_view _value;
|
char* _value;
|
||||||
std::atomic<size_t> _references;
|
std::atomic<size_t> _references;
|
||||||
|
|
||||||
__ConstStringCharHolder(const __ConstStringCharHolder& o) = delete;
|
__ConstStringCharHolder(const __ConstStringCharHolder& o) = delete;
|
||||||
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
__ConstStringCharHolder(const std::string_view& value) noexcept : _value(value), _references(1) {}
|
__ConstStringCharHolder(const std::string_view& value) noexcept
|
||||||
|
: _value(new char[value.length() + 1]), _references(1) {
|
||||||
|
strncpy(_value, value.data(), value.length());
|
||||||
|
_value[value.length()] = '\0';
|
||||||
|
}
|
||||||
|
~__ConstStringCharHolder() { delete[] _value; }
|
||||||
|
|
||||||
inline void RemoveReference() noexcept {
|
inline void RemoveReference() noexcept {
|
||||||
if (--_references <= 0) {
|
if (--_references <= 0) {
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void AddReference() noexcept { _references++; }
|
inline void AddReference() noexcept { _references++; }
|
||||||
inline constexpr const std::string_view& GetValue() const noexcept { return _value; }
|
inline constexpr std::string_view GetValue() const noexcept { return std::string_view(_value); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +45,6 @@ inline static constexpr char charToLower(const char c) { return (c >= 'A' && c <
|
||||||
static uint32_t constexpr Hash(char const* input) {
|
static uint32_t constexpr Hash(char const* input) {
|
||||||
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * Hash(input + 1) : 5381;
|
return charToLower(*input) ? static_cast<uint32_t>(charToLower(*input)) + 33 * Hash(input + 1) : 5381;
|
||||||
};
|
};
|
||||||
static int constexpr CalcLength(const char* str) { return *str ? 1 + CalcLength(str + 1) : 0; }
|
|
||||||
|
|
||||||
namespace ArbUt {
|
namespace ArbUt {
|
||||||
class StringView final : public BasicStringView {
|
class StringView final : public BasicStringView {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "BasicStringView.hpp"
|
#include "BasicStringView.hpp"
|
||||||
#include "StringView.hpp"
|
#include "StringView.hpp"
|
||||||
|
|
||||||
|
static int constexpr CalcLength(const char* str) { return *str ? 1 + CalcLength(str + 1) : 0; }
|
||||||
|
|
||||||
namespace ArbUt {
|
namespace ArbUt {
|
||||||
class StringViewLiteral final : public BasicStringView {
|
class StringViewLiteral final : public BasicStringView {
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue