Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions JSON/include/Poco/JSON/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ class JSON_API Object
bool _lowercaseHex;
mutable StructPtr _pStruct;
mutable OrdStructPtr _pOrdStruct;
mutable bool _modified;
mutable bool _structModified;
mutable bool _ordStructModified;
};


Expand Down Expand Up @@ -488,7 +489,8 @@ inline void Object::remove(const std::string& key)
}
}
_values.erase(key);
_modified = true;
_structModified = true;
_ordStructModified = true;
}


Expand Down
34 changes: 23 additions & 11 deletions JSON/src/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Object::Object(int options):
_preserveInsOrder((options & Poco::JSON_PRESERVE_KEY_ORDER) != 0),
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0),
_lowercaseHex((options & Poco::JSON_LOWERCASE_HEX) != 0),
_modified(false)
_structModified(false),
_ordStructModified(false)
{
}

Expand All @@ -47,8 +48,10 @@ Object::Object(const Object& other) :
_preserveInsOrder(other._preserveInsOrder),
_escapeUnicode(other._escapeUnicode),
_lowercaseHex(other._lowercaseHex),
_pStruct(!other._modified ? other._pStruct : nullptr),
_modified(other._modified)
_pStruct(!other._structModified ? other._pStruct : nullptr),
_pOrdStruct(!other._ordStructModified ? other._pOrdStruct : nullptr),
_structModified(other._structModified),
_ordStructModified(other._ordStructModified)
{
syncKeys(other._keys);
}
Expand All @@ -62,7 +65,8 @@ Object::Object(Object&& other) noexcept:
_lowercaseHex(other._lowercaseHex),
_pStruct(std::move(other._pStruct)),
_pOrdStruct(std::move(other._pOrdStruct)),
_modified(other._modified)
_structModified(other._structModified),
_ordStructModified(other._ordStructModified)
{
}

Expand All @@ -79,8 +83,10 @@ Object &Object::operator = (const Object &other)
_preserveInsOrder = other._preserveInsOrder;
_escapeUnicode = other._escapeUnicode;
_lowercaseHex = other._lowercaseHex;
_pStruct = !other._modified ? other._pStruct : nullptr;
_modified = other._modified;
_pStruct = !other._structModified ? other._pStruct : nullptr;
_pOrdStruct = !other._ordStructModified ? other._pOrdStruct : nullptr;
_structModified = other._structModified;
_ordStructModified = other._ordStructModified;
}
return *this;
}
Expand All @@ -95,7 +101,8 @@ Object& Object::operator = (Object&& other) noexcept
_lowercaseHex = other._lowercaseHex;
_pStruct = std::move(other._pStruct);
_pOrdStruct = std::move(other._pOrdStruct);
_modified = other._modified;
_structModified = other._structModified;
_ordStructModified = other._ordStructModified;

return *this;
}
Expand Down Expand Up @@ -215,7 +222,8 @@ Object& Object::set(const std::string& key, const Dynamic::Var& value)
}
_keys.emplace_back(ret.first);
}
_modified = true;
_structModified = true;
_ordStructModified = true;
return *this;
}

Expand Down Expand Up @@ -258,7 +266,7 @@ Object::operator const Poco::DynamicStruct& () const
{
resetDynStruct(_pStruct);
}
else if (_modified)
else if (_structModified)
{
auto it = _values.begin();
const auto end = _values.end();
Expand All @@ -278,6 +286,7 @@ Object::operator const Poco::DynamicStruct& () const
_pStruct->insert(it->first, it->second);
}
}
_structModified = false;
}

return *_pStruct;
Expand All @@ -290,7 +299,7 @@ Object::operator const Poco::OrderedDynamicStruct& () const
{
resetDynStruct(_pOrdStruct);
}
else if (_modified)
else if (_ordStructModified)
{
if (_preserveInsOrder)
{
Expand Down Expand Up @@ -334,6 +343,7 @@ Object::operator const Poco::OrderedDynamicStruct& () const
}
}
}
_ordStructModified = false;
}

return *_pOrdStruct;
Expand All @@ -345,7 +355,9 @@ void Object::clear()
_values.clear();
_keys.clear();
_pStruct = nullptr;
_modified = true;
_pOrdStruct = nullptr;
_structModified = true;
_ordStructModified = true;
}


Expand Down
Loading