Compress consecutive removals.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Wed, 31 Aug 2011 08:03:43 +0000 (18:03 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 21 Sep 2011 06:23:52 +0000 (08:23 +0200)
If an applied list of changes has consecutive removals compress them
together before applying them to the change set.

Change-Id: I75f178a31bbc8480d76be745c62e824125dbd8ba
Reviewed-on: http://codereview.qt-project.org/4032
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>

src/declarative/util/qdeclarativechangeset.cpp

index a10693f..d941d5e 100644 (file)
@@ -135,6 +135,22 @@ void QDeclarativeChangeSet::applyRemovals(QVector<Remove> &removals, QVector<Ins
 
         QVector<Insert>::iterator iit = insertions.begin();
         for (; rit->moveId != -1 && iit != insertions.end() && iit->moveId != rit->moveId; ++iit) {}
+
+        for (QVector<Remove>::iterator nrit = rit + 1; nrit != removals.end(); nrit = rit + 1) {
+            if (nrit->index != rit->index || (rit->moveId == -1) != (nrit->moveId == -1))
+                break;
+            if (nrit->moveId != -1) {
+                QVector<Insert>::iterator niit = iit + 1;
+                if (niit->moveId != nrit->moveId || niit->index != iit->index + iit->count)
+                    break;
+                niit->index = iit->index;
+                niit->count += iit->count;
+                iit = insertions.erase(iit);
+            }
+            nrit->count += rit->count;
+            rit = removals.erase(rit);
+        }
+
         for (; change != m_changes.end() && change->end() < rit->index; ++change) {}
         for (; change != m_changes.end() && change->index > rit->end(); ++change) {
             change->count -= qMin(change->end(), rit->end()) - qMax(change->index, rit->index);