util/AllocatedString: replace Clone() with copy constructor
This commit is contained in:
parent
8d47f51399
commit
c1a7aa652d
@ -38,11 +38,11 @@ class IcuCompare {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Windows API functions work with wchar_t strings, so let's
|
/* Windows API functions work with wchar_t strings, so let's
|
||||||
cache the MultiByteToWideChar() result for performance */
|
cache the MultiByteToWideChar() result for performance */
|
||||||
BasicAllocatedString<wchar_t> needle;
|
using AllocatedString = BasicAllocatedString<wchar_t>;
|
||||||
#else
|
|
||||||
AllocatedString needle;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
AllocatedString needle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IcuCompare():needle(nullptr) {}
|
IcuCompare():needle(nullptr) {}
|
||||||
|
|
||||||
@ -50,12 +50,12 @@ public:
|
|||||||
|
|
||||||
IcuCompare(const IcuCompare &src) noexcept
|
IcuCompare(const IcuCompare &src) noexcept
|
||||||
:needle(src
|
:needle(src
|
||||||
? src.needle.Clone()
|
? AllocatedString(src.needle)
|
||||||
: nullptr) {}
|
: nullptr) {}
|
||||||
|
|
||||||
IcuCompare &operator=(const IcuCompare &src) noexcept {
|
IcuCompare &operator=(const IcuCompare &src) noexcept {
|
||||||
needle = src
|
needle = src
|
||||||
? src.needle.Clone()
|
? AllocatedString(src.needle)
|
||||||
: nullptr;
|
: nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,9 @@ public:
|
|||||||
explicit BasicAllocatedString(const_pointer src)
|
explicit BasicAllocatedString(const_pointer src)
|
||||||
:value(Duplicate(src)) {}
|
:value(Duplicate(src)) {}
|
||||||
|
|
||||||
|
BasicAllocatedString(const BasicAllocatedString &src) noexcept
|
||||||
|
:BasicAllocatedString(Duplicate(src.value)) {}
|
||||||
|
|
||||||
BasicAllocatedString(BasicAllocatedString &&src) noexcept
|
BasicAllocatedString(BasicAllocatedString &&src) noexcept
|
||||||
:value(src.Steal()) {}
|
:value(src.Steal()) {}
|
||||||
|
|
||||||
@ -137,10 +140,6 @@ public:
|
|||||||
return std::exchange(value, nullptr);
|
return std::exchange(value, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicAllocatedString Clone() const {
|
|
||||||
return BasicAllocatedString(Duplicate(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static pointer Duplicate(string_view src) {
|
static pointer Duplicate(string_view src) {
|
||||||
auto p = new value_type[src.size() + 1];
|
auto p = new value_type[src.size() + 1];
|
||||||
@ -150,7 +149,7 @@ private:
|
|||||||
|
|
||||||
static pointer Duplicate(const_pointer src) {
|
static pointer Duplicate(const_pointer src) {
|
||||||
return src != nullptr
|
return src != nullptr
|
||||||
? Duplicate(std::string_view(src))
|
? Duplicate(string_view(src))
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user