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 {
|
||||
class __ConstStringCharHolder {
|
||||
std::string_view _value;
|
||||
char* _value;
|
||||
std::atomic<size_t> _references;
|
||||
|
||||
__ConstStringCharHolder(const __ConstStringCharHolder& o) = delete;
|
||||
__ConstStringCharHolder& operator=(const __ConstStringCharHolder& other) = delete;
|
||||
|
||||
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 {
|
||||
if (--_references <= 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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 {
|
||||
class StringView final : public BasicStringView {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "BasicStringView.hpp"
|
||||
#include "StringView.hpp"
|
||||
|
||||
static int constexpr CalcLength(const char* str) { return *str ? 1 + CalcLength(str + 1) : 0; }
|
||||
|
||||
namespace ArbUt {
|
||||
class StringViewLiteral final : public BasicStringView {
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue