diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2013-10-05 01:12:36 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-26 22:02:28 +0100 |
commit | 1e4d70b5b626f70c6d36731c08c2367febf95f27 (patch) | |
tree | 68b76b7081d9914d5cbd9b03968e95ac928d9651 /src/widgets/widgets/qmdiarea.cpp | |
parent | 0abc35b5f78d6d0f2fd958ea550e8e4b238fddfb (diff) |
QMdiArea: replace dubious use of QSet<int> with QVector
The code populated two QSets with some x and y coordinates and went
on to get the values as a list. Since QSet is unordered_set, those
lists were not sorted, so the code did that manually. It then went
and created the cross product of the two lists as a list of QPoints.
Since QSet is a node-based container and not even an ordered one,
the code pays a hefty price just for ensuring uniqueness of values
prior to sorting.
The new code just cramms everything into vectors, duplicates and all,
then sorts the vectors and only then removes duplicates using
std::unique. Since the sizes of all containers involved are known
ahead of time, make liberal use of reserve() to trim the whole
container business down to three memory allocations.
Change-Id: I7004b1b90b3142acb12d7bb12bcd0014d54e6e02
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/widgets/widgets/qmdiarea.cpp')
-rw-r--r-- | src/widgets/widgets/qmdiarea.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index cb5c8751cf..f06370bbcf 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -450,22 +450,28 @@ QRect MinOverlapPlacer::findMinOverlapRect(const QVector<QRect> &source, const Q void MinOverlapPlacer::getCandidatePlacements(const QSize &size, const QVector<QRect> &rects, const QRect &domain,QVector<QRect> &candidates) { - QSet<int> xset; - QSet<int> yset; - xset << domain.left() << domain.right() - size.width() + 1; - yset << domain.top(); + QVector<int> xlist; + xlist.reserve(2 + rects.size()); + xlist << domain.left() << domain.right() - size.width() + 1; + + QVector<int> ylist; + ylist.reserve(2 + rects.size()); + ylist << domain.top(); if (domain.bottom() - size.height() + 1 >= 0) - yset << domain.bottom() - size.height() + 1; + ylist << domain.bottom() - size.height() + 1; + foreach (const QRect &rect, rects) { - xset << rect.right() + 1; - yset << rect.bottom() + 1; + xlist << rect.right() + 1; + ylist << rect.bottom() + 1; } - QList<int> xlist = xset.values(); std::sort(xlist.begin(), xlist.end()); - QList<int> ylist = yset.values(); + xlist.erase(std::unique(xlist.begin(), xlist.end()), xlist.end()); + std::sort(ylist.begin(), ylist.end()); + ylist.erase(std::unique(ylist.begin(), ylist.end()), ylist.end()); + candidates.reserve(candidates.size() + ylist.size() * xlist.size()); foreach (int y, ylist) foreach (int x, xlist) candidates << QRect(QPoint(x, y), size); |