From a158277f9e7d60e3076bf9fe5912a57b2c297394 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 25 Aug 2016 12:21:01 +0200 Subject: 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 --- src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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 & for (const AnchorData *ad : visited) identifyNonFloatItems_helper(ad, &nonFloating); - QSet allItems; - foreach (QGraphicsLayoutItem *item, items) - allItems.insert(item); - m_floatItems[orientation] = allItems - nonFloating; + QSet floatItems; + for (QGraphicsLayoutItem *item : qAsConst(items)) { + if (!nonFloating.contains(item)) + floatItems.insert(item); + } + m_floatItems[orientation] = std::move(floatItems); } -- cgit v1.2.3