cn/r part 2 of 2.

This commit is contained in:
XMRig 2019-09-04 11:23:04 +07:00
parent b9e15389ca
commit 57f82f7504
16 changed files with 287 additions and 139 deletions

View file

@ -31,7 +31,6 @@
xmrig::String::String(const char *str) :
m_data(nullptr),
m_size(str == nullptr ? 0 : strlen(str))
{
if (m_size == 0) {
@ -44,7 +43,6 @@ xmrig::String::String(const char *str) :
xmrig::String::String(const char *str, size_t size) :
m_data(nullptr),
m_size(size)
{
if (str == nullptr) {
@ -60,7 +58,6 @@ xmrig::String::String(const char *str, size_t size) :
xmrig::String::String(const String &other) :
m_data(nullptr),
m_size(other.m_size)
{
if (other.m_data == nullptr) {
@ -117,7 +114,7 @@ std::vector<xmrig::String> xmrig::String::split(char sep) const
for (pos = 0; pos < m_size; ++pos) {
if (m_data[pos] == sep) {
if ((pos - start) > 0) {
out.push_back(String(m_data + start, pos - start));
out.emplace_back(m_data + start, pos - start);
}
start = pos + 1;
@ -125,7 +122,7 @@ std::vector<xmrig::String> xmrig::String::split(char sep) const
}
if ((pos - start) > 0) {
out.push_back(String(m_data + start, pos - start));
out.emplace_back(m_data + start, pos - start);
}
return out;

View file

@ -46,9 +46,9 @@ namespace xmrig {
class String
{
public:
inline String() : m_data(nullptr), m_size(0) {}
inline String(char *str) : m_data(str), m_size(str == nullptr ? 0 : strlen(str)) {}
inline String(String &&other) : m_data(other.m_data), m_size(other.m_size) { other.m_data = nullptr; other.m_size = 0; }
inline String() = default;
inline String(char *str) : m_data(str), m_size(str == nullptr ? 0 : strlen(str)) {}
inline String(String &&other) noexcept : m_data(other.m_data), m_size(other.m_size) { other.m_data = nullptr; other.m_size = 0; }
String(const char *str);
String(const char *str, size_t size);
@ -81,7 +81,7 @@ public:
inline String &operator=(const char *str) { copy(str); return *this; }
inline String &operator=(const String &str) { copy(str); return *this; }
inline String &operator=(std::nullptr_t) { delete [] m_data; m_data = nullptr; m_size = 0; return *this; }
inline String &operator=(String &&other) { move(std::move(other)); return *this; }
inline String &operator=(String &&other) noexcept { move(std::move(other)); return *this; }
rapidjson::Value toJSON() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
@ -97,8 +97,8 @@ private:
void move(char *str);
void move(String &&other);
char *m_data;
size_t m_size;
char *m_data = nullptr;
size_t m_size = 0;
};