From 5994299baa1cd66c3231a4a1d106152e0d7fb8d0 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 27 Jun 2020 15:15:13 +0200 Subject: [PATCH] Further tweaks to StringViews. --- src/String/StringView.hpp | 8 ++++---- src/String/StringViewLiteral.hpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/String/StringView.hpp b/src/String/StringView.hpp index 221c56d..788e5f3 100644 --- a/src/String/StringView.hpp +++ b/src/String/StringView.hpp @@ -65,14 +65,14 @@ namespace ArbUt { : BasicStringView(CalcLength(str), Hash(str)), _str(new __ConstStringCharHolder(str, CalcLength(str))) {} StringView(const char* str, size_t length) noexcept : BasicStringView(length, Hash(str)), _str(new __ConstStringCharHolder(str, length)) {} - - StringView() noexcept : BasicStringView(0, Hash("")), _str(GetEmptyString()) { - GetEmptyString()->AddReference(); - } + StringView() noexcept : BasicStringView(0, Hash("")), _str(GetEmptyString()) { _str->AddReference(); } /* Copy operators */ StringView(const StringView& other) noexcept : BasicStringView(other._length, other._hash), _str(other.CloneHolder()) {} + StringView(const BasicStringView& other, const char* c, size_t length) noexcept + : BasicStringView(length, other.GetHash()), _str(new __ConstStringCharHolder(c, length)) {} + StringView& operator=(const StringView& other) noexcept { if (_str == other._str) { _str->AddReference(); diff --git a/src/String/StringViewLiteral.hpp b/src/String/StringViewLiteral.hpp index 01e14f5..7031504 100644 --- a/src/String/StringViewLiteral.hpp +++ b/src/String/StringViewLiteral.hpp @@ -17,7 +17,7 @@ namespace ArbUt { [[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str; } constexpr std::string_view std_str() const noexcept { return std::string_view(_str, _length); } constexpr std::size_t operator()(StringViewLiteral const& s) const noexcept { return s.GetHash(); } - inline operator StringView() const noexcept { return StringView(_str, _length); } + inline operator StringView() const noexcept { return StringView(*this, _str, _length); } inline constexpr bool operator==(const std::string_view& rhs) const noexcept { return _hash == Hash(rhs.data());