path: root/src/widgets/graphicsview
diff options
authorMarc Mutz <>2016-08-25 12:21:01 +0200
committerMarc Mutz <>2016-08-25 13:39:57 +0000
commita158277f9e7d60e3076bf9fe5912a57b2c297394 (patch)
tree42d15bab7116c70225e6f63ece9de150f61a1b40 /src/widgets/graphicsview
parentf32dfc9125b04c725adf95e5803555cf1e74d00a (diff)
QGraphicsAnchorLayout: don't build a QSet just for building a set difference
op- takes a copy of the LHS, and calls subtract() on it. That means that the old code not only added more nodes to the set than necessary (wasting memory when nodes are removed again), but also takes a deep copy of the large LHS container. Fix by building the final set ourselves selectively. This avoids creation of useless nodes, as well as the deep copy. Port Q_FOREACH loop to C++11 range-for as a drive-by. Change-Id: I9c83af02159a7d29ff5c2e7c3a4952a735c32af3 Reviewed-by: Friedemann Kleint <>
Diffstat (limited to 'src/widgets/graphicsview')
1 files changed, 6 insertions, 4 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
index 4c01219d87..02956b76f9 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -2575,10 +2575,12 @@ void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &
for (const AnchorData *ad : visited)
identifyNonFloatItems_helper(ad, &nonFloating);
- QSet<QGraphicsLayoutItem *> allItems;
- foreach (QGraphicsLayoutItem *item, items)
- allItems.insert(item);
- m_floatItems[orientation] = allItems - nonFloating;
+ QSet<QGraphicsLayoutItem *> floatItems;
+ for (QGraphicsLayoutItem *item : qAsConst(items)) {
+ if (!nonFloating.contains(item))
+ floatItems.insert(item);
+ }
+ m_floatItems[orientation] = std::move(floatItems);