diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-30 12:19:31 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-12-23 09:14:03 +0000 |
commit | 4e628397b0ef6f8d5e9294e85507488cebe740f3 (patch) | |
tree | 47e39ade7cf381fd862e0d399811b997fd83b22e /src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | |
parent | 29ddfc3be730ca48cbec0e3b4508b006ba79eb66 (diff) |
QGraphicsView: replace some Q_FOREACH loops over rvalues with C++11 range-for
This needs to be handled a bit carefully, because Qt containers
will detach upon being iterated over using range-for.
In the cases of this patch, that trivially cannot happen, because
all containers are marked as const when being assigned the rvalues
previously found on the rhs of the Q_FOREACH. The new code thus
does exactly what the old code did: take a const copy, then iterate
over it.
Separate patches will deal with other situations.
Range-for loops are much more efficient than foreach loops.
This patch shaves almost 4K of text size off an optimized Linux
AMD64 GCC 4.9 build.
Change-Id: Ida868b77d078cbfa0516d17e98e6f0a86fcdb7a3
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index e16b427448..adc77ded47 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -2318,9 +2318,9 @@ void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation) graphPaths[orientation].insert(root, GraphPath()); - foreach (AnchorVertex *v, graph[orientation].adjacentVertices(root)) { + const auto adjacentVertices = graph[orientation].adjacentVertices(root); + for (AnchorVertex *v : adjacentVertices) queue.enqueue(qMakePair(root, v)); - } while(!queue.isEmpty()) { QPair<AnchorVertex *, AnchorVertex *> pair = queue.dequeue(); @@ -2339,10 +2339,9 @@ void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation) graphPaths[orientation].insert(pair.second, current); - foreach (AnchorVertex *v, - graph[orientation].adjacentVertices(pair.second)) { + const auto adjacentVertices = graph[orientation].adjacentVertices(pair.second); + for (AnchorVertex *v : adjacentVertices) queue.enqueue(qMakePair(pair.second, v)); - } } // We will walk through every reachable items (non-float) store them in a temporary set. @@ -2703,9 +2702,9 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions( visited.insert(root); // Add initial edges to the queue - foreach (AnchorVertex *v, graph[orientation].adjacentVertices(root)) { + const auto adjacentVertices = graph[orientation].adjacentVertices(root); + for (AnchorVertex *v : adjacentVertices) queue.enqueue(qMakePair(root, v)); - } // Do initial calculation required by "interpolateEdge()" setupEdgesInterpolation(orientation); |