aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlnotifier
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2015-07-13 14:57:16 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-07-21 12:04:27 +0000
commit40b9fb8946837a01710814c28fd0f04edba631ad (patch)
tree37ab859f436870e1add2f028b671caffede3f21e /tests/auto/qml/qqmlnotifier
parent96c35a84d30b5b5cdf8feac4959891ad0bfed6a8 (diff)
Fix possible stack overflow with many property bindings
When there are a lot of bindings to the same property (like 20 000), we would get stack overflows because the notify list for the changed signal was traversed recursively. Changing this also speeds up the traversal. I see something like ~40% reduction in the case of layout() for a notify list of around 200 items. Note: To make it possible to traverse the double-linked list backwards, the next-pointer needs to be moved to the beginning of the struct, because the implementation pattern assumes this (node->next->prev = &node->next). I think this code has rotted after it was added, since the prev pointer was never actually used anywhere before. Change-Id: Icdfac50b7c8584a908efa65694c7f5f416cb153b Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlnotifier')
-rw-r--r--tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
index 81215f7a18..4f1c9ae53e 100644
--- a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
+++ b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
@@ -165,6 +165,7 @@ private slots:
void readProperty();
void propertyChange();
void disconnectOnDestroy();
+ void lotsOfBindings();
private:
void createObjects();
@@ -312,6 +313,39 @@ void tst_qqmlnotifier::disconnectOnDestroy()
exportedObject->verifyReceiverCount();
}
+class TestObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int a READ a NOTIFY aChanged)
+
+public:
+ int a() const { return 0; }
+
+signals:
+ void aChanged();
+};
+
+void tst_qqmlnotifier::lotsOfBindings()
+{
+ TestObject o;
+ QQmlEngine *e = new QQmlEngine;
+
+ e->rootContext()->setContextProperty(QStringLiteral("test"), &o);
+
+ QList<QQmlComponent *> components;
+ for (int i = 0; i < 20000; ++i) {
+ QQmlComponent *component = new QQmlComponent(e);
+ component->setData("import QtQuick 2.0; Item { width: test.a; }", QUrl());
+ component->create(e->rootContext());
+ components.append(component);
+ }
+
+ o.aChanged();
+
+ qDeleteAll(components);
+ delete e;
+}
+
QTEST_MAIN(tst_qqmlnotifier)
#include "tst_qqmlnotifier.moc"