aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlengine.cpp
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 /src/qml/qml/qqmlengine.cpp
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 'src/qml/qml/qqmlengine.cpp')
-rw-r--r--src/qml/qml/qqmlengine.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 1f27e4ecb3..392cbe9371 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -1540,16 +1540,28 @@ QQmlDataExtended::~QQmlDataExtended()
void QQmlData::NotifyList::layout(QQmlNotifierEndpoint *endpoint)
{
- if (endpoint->next)
- layout(endpoint->next);
+ // Add a temporary sentinel at beginning of list. This will be overwritten
+ // when the end point is inserted into the notifies further down.
+ endpoint->prev = 0;
- int index = endpoint->sourceSignal;
- index = qMin(index, 0xFFFF - 1);
+ while (endpoint->next) {
+ Q_ASSERT(reinterpret_cast<QQmlNotifierEndpoint *>(endpoint->next->prev) == endpoint);
+ endpoint = endpoint->next;
+ }
+
+ while (endpoint) {
+ QQmlNotifierEndpoint *ep = (QQmlNotifierEndpoint *) endpoint->prev;
+
+ int index = endpoint->sourceSignal;
+ index = qMin(index, 0xFFFF - 1);
- endpoint->next = notifies[index];
- if (endpoint->next) endpoint->next->prev = &endpoint->next;
- endpoint->prev = &notifies[index];
- notifies[index] = endpoint;
+ endpoint->next = notifies[index];
+ if (endpoint->next) endpoint->next->prev = &endpoint->next;
+ endpoint->prev = &notifies[index];
+ notifies[index] = endpoint;
+
+ endpoint = ep;
+ }
}
void QQmlData::NotifyList::layout()