diff options
author | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2014-09-10 10:52:14 +0200 |
---|---|---|
committer | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2014-09-11 10:54:42 +0200 |
commit | fa9a407b9f7b89e4785c650dcb3e80d08ea3c042 (patch) | |
tree | 87a85efb95e21e248b95904b834370b956e804b6 /src/corelib/json/qjsonobject.cpp | |
parent | 7b9f7f3891230ddd2b2ef5cf3c760a605a02ee96 (diff) |
Revert "Reading QJsonObject property should not modify the object itself."
This reverts commit 20cf632ad5f3ffe7b0fd231724c971f4e07304eb. The commit
produced to many problems during statics destruction. For example
causing QtCreator crash (QTBUG-40987).
Change-Id: Ib52f6a449c2d84deab2de792559a6a065ca45e8d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/json/qjsonobject.cpp')
-rw-r--r-- | src/corelib/json/qjsonobject.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index b393701411..00cc2ddbd3 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -161,7 +161,6 @@ QJsonObject::~QJsonObject() { if (d && !d->ref.deref()) delete d; - QJsonPrivate::ObjectUndefinedKeys::removeKeys(this); // ### Qt6 move it to ~QJsonValueRef } /*! @@ -318,9 +317,14 @@ QJsonValue QJsonObject::operator [](const QString &key) const */ QJsonValueRef QJsonObject::operator [](const QString &key) { + // ### somewhat inefficient, as we lookup the key twice if it doesn't yet exist bool keyExists = false; int index = o ? o->indexOf(key, &keyExists) : -1; - return keyExists ? QJsonValueRef(this, index) : QJsonValueRef(this, key); + if (!keyExists) { + iterator i = insert(key, QJsonValue()); + index = i.i; + } + return QJsonValueRef(this, index); } /*! @@ -1034,9 +1038,7 @@ void QJsonObject::compact() detach(); d->compact(); - using namespace QJsonPrivate; - o = static_cast<Object *>(d->header->root()); - ObjectUndefinedKeys::removeKeys(this); // ### Qt6 move it to ~QJsonValueRef + o = static_cast<QJsonPrivate::Object *>(d->header->root()); } /*! @@ -1073,8 +1075,6 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val) insert(e->key(), val); } -QBasicMutex QJsonPrivate::ObjectUndefinedKeys::mutex; - #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) QDebug operator<<(QDebug dbg, const QJsonObject &o) { |