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 #include +#include + QT_BEGIN_NAMESPACE static inline int intmaxlog(int n) @@ -545,23 +547,18 @@ QList QGraphicsSceneBspTreeIndex::items(Qt::SortOrder order) co Q_D(const QGraphicsSceneBspTreeIndex); const_cast(d)->purgeRemovedItems(); QList 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 + // 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; }