code cleanup; fix move ctors and assignment

This commit is contained in:
Günter Obiltschnig
2020-01-21 17:52:43 +01:00
parent de52e23d12
commit 18adb1e43b
20 changed files with 327 additions and 188 deletions

View File

@@ -25,46 +25,50 @@ namespace Poco {
namespace JSON {
Array::Array(int options): _modified(false),
Array::Array(int options):
_modified(false),
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0)
{
}
Array::Array(const Array& other) : _values(other._values),
Array::Array(const Array& other) :
_values(other._values),
_pArray(other._pArray),
_modified(other._modified)
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
{
}
Array &Array::operator=(const Array& other)
Array::Array(Array&& other) noexcept:
_values(std::move(other._values)),
_pArray(std::move(other._pArray)),
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
{
}
Array& Array::operator = (const Array& other)
{
if (&other != this)
{
_values = other._values;
_pArray = other._pArray;
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
}
return *this;
}
Array::Array(Array&& other):
_values(std::move(other._values)),
_pArray(!other._modified ? other._pArray : 0),
_modified(other._modified)
{
_pArray = 0;
}
Array &Array::operator = (Array&& other)
Array& Array::operator = (Array&& other) noexcept
{
_values = std::move(other._values);
_pArray = other._pArray;
other._pArray = 0;
_pArray = std::move(other._pArray);
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
return *this;
}

View File

@@ -42,29 +42,15 @@ Object::Object(const Object& other) : _values(other._values),
}
Object::Object(Object&& other):
Object::Object(Object&& other) noexcept:
_values(std::move(other._values)),
_keys(std::move(other._keys)),
_preserveInsOrder(other._preserveInsOrder),
_escapeUnicode(other._escapeUnicode),
_pStruct(!other._modified ? other._pStruct : 0),
_pStruct(std::move(other._pStruct)),
_pOrdStruct(std::move(other._pOrdStruct)),
_modified(other._modified)
{
other.clear();
}
Object &Object::operator = (Object&& other)
{
_values = other._values;
_preserveInsOrder = other._preserveInsOrder;
syncKeys(other._keys);
_escapeUnicode = other._escapeUnicode;
_pStruct = !other._modified ? other._pStruct : 0;
_modified = other._modified;
other.clear();
return *this;
}
@@ -73,7 +59,7 @@ Object::~Object()
}
Object &Object::operator= (const Object &other)
Object &Object::operator = (const Object &other)
{
if (&other != this)
{
@@ -88,6 +74,20 @@ Object &Object::operator= (const Object &other)
}
Object& Object::operator = (Object&& other) noexcept
{
_values = std::move(other._values);
_keys = std::move(other._keys);
_preserveInsOrder = other._preserveInsOrder;
_escapeUnicode = other._escapeUnicode;
_pStruct = std::move(other._pStruct);
_pOrdStruct = std::move(other._pOrdStruct);
_modified = other._modified;
return *this;
}
void Object::syncKeys(const KeyList& keys)
{
if(_preserveInsOrder)