aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlqt
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-04-28 11:09:41 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-05-11 12:23:17 +0000
commit28128f2dc6c5eb63d52658ede840e02b06f9ac2c (patch)
treefee0d69ebf243f41a2567ea3942bcf8c42a07aeb /tests/auto/qml/qqmlqt
parent39ce4c70e7cfc6b761c2172fe9b048027c220af4 (diff)
QML: Fill QtObject lazily.
Only iterate over the enumerations/enumerators in the staticQtMetaObject when a get() is done, and the key/value is not yet in stored in the underlying Object. The whole cost of the iteration is now moved to get() and advanceIterator(). The latter will add all items in one swoop, but iteration over QtObject isn't used much (if at all). The get() will add all key/value pairs up until it finds the requested key. Checking a number of applications shows that none of them use all (or the "last") key, so it will actually save entries (which equals memory) too. This change reduces the instruction count for QtObject from 2.7M instructions down to 95k. As this initialization is done from the QQmlEngine constructor, it also speeds up that initialization. Task-number: QTBUG-43770 Change-Id: I71331ff76bdacdd4790f7ff0430c4cbc214fe0ab Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlqt')
-rw-r--r--tests/auto/qml/qqmlqt/data/qtObjectContents.qml10
-rw-r--r--tests/auto/qml/qqmlqt/tst_qqmlqt.cpp46
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlqt/data/qtObjectContents.qml b/tests/auto/qml/qqmlqt/data/qtObjectContents.qml
new file mode 100644
index 0000000000..c85e7986e9
--- /dev/null
+++ b/tests/auto/qml/qqmlqt/data/qtObjectContents.qml
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+
+QtObject {
+ property var values: Object()
+ Component.onCompleted: {
+ for (var key in Qt) {
+ values[key] = Qt[key]
+ }
+ }
+}
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
index 01283dd587..2f44c34bc2 100644
--- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
+++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
@@ -87,6 +87,7 @@ private slots:
void fontFamilies();
void quit();
void resolvedUrl();
+ void qtObjectContents();
private:
QQmlEngine engine;
@@ -934,6 +935,51 @@ void tst_qqmlqt::resolvedUrl()
delete object;
}
+void tst_qqmlqt::qtObjectContents()
+{
+ struct StaticQtMetaObject : public QObject
+ {
+ static const QMetaObject *get()
+ { return &staticQtMetaObject; }
+ };
+
+ QQmlComponent component(&engine, testFileUrl("qtObjectContents.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QVERIFY(object->property("values").canConvert<QJSValue>());
+ QVariantMap values = object->property("values").value<QJSValue>().toVariant().toMap();
+
+ QSet<const char *> keys;
+ int uniqueKeys = 0;
+ const QMetaObject *qtMetaObject = StaticQtMetaObject::get();
+ for (int ii = 0; ii < qtMetaObject->enumeratorCount(); ++ii) {
+ QMetaEnum enumerator = qtMetaObject->enumerator(ii);
+ for (int jj = 0; jj < enumerator.keyCount(); ++jj) {
+ auto key = enumerator.key(jj);
+// qDebug() << "key:" << key;
+ if (!keys.contains(key)) {
+ ++uniqueKeys;
+ keys.insert(key);
+ }
+ QVERIFY(values.contains(key));
+ QVariant value = values.value(key);
+ QVERIFY(value.canConvert<int>());
+ QCOMPARE(value.toInt(), enumerator.value(jj));
+ }
+ }
+ QVERIFY(values.contains("Asynchronous"));
+ QCOMPARE(values.value("Asynchronous").toInt(), 0);
+ ++uniqueKeys;
+ QVERIFY(values.contains("Synchronous"));
+ QCOMPARE(values.value("Synchronous").toInt(), 1);
+ ++uniqueKeys;
+ QCOMPARE(values.count(), uniqueKeys);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlqt)
#include "tst_qqmlqt.moc"