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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Marc Mutz 2016-08-25 12:21:01 +02:00
parent f32dfc9125
commit a158277f9e

View File

@ -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);
}