summaryrefslogtreecommitdiffstats
path: root/src/corelib/json/qjsonobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/json/qjsonobject.cpp')
-rw-r--r--src/corelib/json/qjsonobject.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp
index 27e51cf4ac..cfd797990f 100644
--- a/src/corelib/json/qjsonobject.cpp
+++ b/src/corelib/json/qjsonobject.cpp
@@ -116,6 +116,20 @@ QJsonObject::QJsonObject()
}
/*!
+ \fn QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args)
+ \since 5.4
+ Constructs a QJsonObject instance initialized from \a args initialization list.
+ For example:
+ \code
+ QJsonObject object
+ {
+ {"property1", 1},
+ {"property2", 2}
+ };
+ \endcode
+*/
+
+/*!
\internal
*/
QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object)
@@ -126,6 +140,19 @@ QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object)
d->ref.ref();
}
+/*!
+ This method replaces part of the QJsonObject(std::initializer_list<QPair<QString, QJsonValue>> args) body.
+ The constructor needs to be inline, but we do not want to leak implementation details
+ of this class.
+ \note this method is called for an uninitialized object
+ \internal
+ */
+
+void QJsonObject::initialize()
+{
+ d = 0;
+ o = 0;
+}
/*!
Destroys the object.
@@ -134,6 +161,7 @@ QJsonObject::~QJsonObject()
{
if (d && !d->ref.deref())
delete d;
+ QJsonPrivate::ObjectUndefinedKeys::removeKeys(this); // ### Qt6 move it to ~QJsonValueRef
}
/*!
@@ -254,7 +282,7 @@ bool QJsonObject::isEmpty() const
QJsonValue QJsonObject::value(const QString &key) const
{
if (!d)
- return QJsonValue();
+ return QJsonValue(QJsonValue::Undefined);
bool keyExists;
int i = o->indexOf(key, &keyExists);
@@ -290,14 +318,9 @@ 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;
- if (!keyExists) {
- iterator i = insert(key, QJsonValue());
- index = i.i;
- }
- return QJsonValueRef(this, index);
+ return keyExists ? QJsonValueRef(this, index) : QJsonValueRef(this, key);
}
/*!
@@ -1001,7 +1024,9 @@ void QJsonObject::compact()
detach();
d->compact();
- o = static_cast<QJsonPrivate::Object *>(d->header->root());
+ using namespace QJsonPrivate;
+ o = static_cast<Object *>(d->header->root());
+ ObjectUndefinedKeys::removeKeys(this); // ### Qt6 move it to ~QJsonValueRef
}
/*!
@@ -1038,6 +1063,8 @@ 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)
{