aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-01-15 11:30:26 +0100
committerLars Knoll <lars.knoll@qt.io>2018-01-15 13:08:59 +0000
commit52874a0e6f739ce410c8401e19b0a9ef6d02cabf (patch)
tree1baf9aaeb7484978930fd1abe4f4fd8dc68bbc4c
parentceba0c6b9a0ac3b50f460572ba95bbbedbbaccae (diff)
Optimizations for Repeater::clear() and ~QQmlItem()
QQmlRepeater::clear() had quadratic complexity in the number of items, because the items where removed from the back. Fix this by searching the cache from the back as well as searching for child items to remove from the back. Change-Id: I92e491a8abf47cee9d382ef15cd2471f722fa6dd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp2
-rw-r--r--src/quick/items/qquickitem.cpp6
2 files changed, 4 insertions, 4 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 2f8a70d63b..f1b5759a7d 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -864,7 +864,7 @@ void QQmlDelegateModelPrivate::releaseIncubator(QQDMIncubationTask *incubationTa
void QQmlDelegateModelPrivate::removeCacheItem(QQmlDelegateModelItem *cacheItem)
{
- int cidx = m_cache.indexOf(cacheItem);
+ int cidx = m_cache.lastIndexOf(cacheItem);
if (cidx >= 0) {
m_compositor.clearFlags(Compositor::Cache, cidx, 1, Compositor::CacheFlag);
m_cache.removeAt(cidx);
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index af60ab879b..54cb8be5da 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2375,9 +2375,8 @@ QQuickItem::~QQuickItem()
else if (d->window)
d->derefWindow();
- // XXX todo - optimize
while (!d->childItems.isEmpty())
- d->childItems.constFirst()->setParentItem(0);
+ d->childItems.constLast()->setParentItem(0);
if (!d->changeListeners.isEmpty()) {
const auto listeners = d->changeListeners; // NOTE: intentional copy (QTBUG-54732)
@@ -2953,7 +2952,8 @@ void QQuickItemPrivate::removeChild(QQuickItem *child)
Q_ASSERT(child);
Q_ASSERT(childItems.contains(child));
- childItems.removeOne(child);
+ int idx = childItems.lastIndexOf(child);
+ childItems.removeAt(idx);
Q_ASSERT(!childItems.contains(child));
QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);