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>
This commit is contained in:
parent
0abc35b5f7
commit
1e4d70b5b6
@ -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();
|
||||
std::sort(ylist.begin(), ylist.end());
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user