diff options
author | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2014-06-26 13:02:54 +0200 |
---|---|---|
committer | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2014-07-25 15:25:17 +0200 |
commit | 20cf632ad5f3ffe7b0fd231724c971f4e07304eb (patch) | |
tree | 6c393d91728928e5aaa33c64fea6a1797dcde7b9 /src/corelib/json/qjsonvalue.cpp | |
parent | c8edde3b833cb3d15377afed13d6fcd2e5fa5cd9 (diff) |
Reading QJsonObject property should not modify the object itself.
Before this change such code:
QJsonObject o;
o["blah"];
would create property "blah" and assign null value to it, while
this code:
const QJsonObject o;
o["blah"];
would not. The change unifies the confusing behavior. Now reading
a non-existing property, is not causing a property to be added
in any visible way.
Internally QJsonObject stores a special hash of undefined, but
referenced values. Such reference is supposed to not live long,
only to the first compacting or assignment.
Change-Id: Ib022acf74ff49bad88d45d65d7093c4281d468f1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/json/qjsonvalue.cpp')
-rw-r--r-- | src/corelib/json/qjsonvalue.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index 4c4838d314..1224a24709 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -669,11 +669,10 @@ void QJsonValue::detach() However, they are not explicitly documented here. */ - QJsonValueRef &QJsonValueRef::operator =(const QJsonValue &val) { if (is_object) - o->setValueAt(index, val); + UnionHelper::setValueAt(this, val); else a->replace(index, val); @@ -683,7 +682,7 @@ QJsonValueRef &QJsonValueRef::operator =(const QJsonValue &val) QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref) { if (is_object) - o->setValueAt(index, ref); + UnionHelper::setValueAt(this, ref); else a->replace(index, ref); @@ -704,7 +703,7 @@ QJsonValue QJsonValueRef::toValue() const { if (!is_object) return a->at(index); - return o->valueAt(index); + return UnionHelper::valueAt(this); } #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) |