summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-21 16:23:12 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-12-22 12:17:33 +0000
commit7353be1c6772dd1295fb5173298bd37ba8f6d1ca (patch)
treee898a66430db2e32eb278448361f5c7e8e39fa39 /src/widgets/graphicsview
parent3690bcfda3e7c28789e1499996adfffde87ba150 (diff)
QGraphicsSceneBspTreeIndex: simplify the code of items()
The old code dealt with a lot of special cases, probably to avoid detaching. But the only case where deep copies are avoided is if a) there're no freeItemIndexes b) there're no unindexedItems c) the sort order is neither AcendingOrder nor DescendingOrder, which is funny, since those are the only two values for Qt::SortOrder. The code checks for SortOrder(-1), but nowhere in Qt is such a sort order created. Ergo, the deep copy was _never_ avoided. So simplify the code by always building the result list from the two input lists by copying all non-null items. Saves over 2KiB in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I8e739fb78896b2ad0bec45d05e86a76fe1ede04a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r--src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp
index ce43b1332d..47d599278a 100644
--- a/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp
+++ b/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp
@@ -77,6 +77,8 @@
#include <QtCore/qmath.h>
#include <QtCore/qdebug.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
static inline int intmaxlog(int n)
@@ -545,23 +547,18 @@ QList<QGraphicsItem *> QGraphicsSceneBspTreeIndex::items(Qt::SortOrder order) co
Q_D(const QGraphicsSceneBspTreeIndex);
const_cast<QGraphicsSceneBspTreeIndexPrivate*>(d)->purgeRemovedItems();
QList<QGraphicsItem *> itemList;
+ itemList.reserve(d->indexedItems.size() + d->unindexedItems.size());
+
+ // Rebuild the list of items to avoid holes. ### We could also just
+ // compress the item lists at this point.
+ QGraphicsItem *null = nullptr; // work-around for (at least) MSVC 2012 emitting
+ // warning C4100 for its own header <algorithm>
+ // when passing nullptr directly to remove_copy:
+ std::remove_copy(d->indexedItems.cbegin(), d->indexedItems.cend(),
+ std::back_inserter(itemList), null);
+ std::remove_copy(d->unindexedItems.cbegin(), d->unindexedItems.cend(),
+ std::back_inserter(itemList), null);
- // If freeItemIndexes is empty, we know there are no holes in indexedItems and
- // unindexedItems.
- if (d->freeItemIndexes.isEmpty()) {
- if (d->unindexedItems.isEmpty()) {
- itemList = d->indexedItems;
- } else {
- itemList = d->indexedItems + d->unindexedItems;
- }
- } else {
- // Rebuild the list of items to avoid holes. ### We could also just
- // compress the item lists at this point.
- foreach (QGraphicsItem *item, d->indexedItems + d->unindexedItems) {
- if (item)
- itemList << item;
- }
- }
d->sortItems(&itemList, order, d->sortCacheEnabled);
return itemList;
}