Replace some QList<int> with QVector<int>

On 64-bit platforms, QVector<int> uses only 50% of QList<int>
per-element memory.

Change-Id: I3057781e7fb58007ea2619cc91965a626d01473b
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-06-15 15:06:56 +02:00
parent f049546d95
commit b034a14dc5
5 changed files with 15 additions and 15 deletions

View File

@ -1653,7 +1653,7 @@ QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const
qDebug() << " bounds" << i << bounds.at(i); qDebug() << " bounds" << i << bounds.at(i);
#endif #endif
QVector< QList<int> > isects; QVector< QVector<int> > isects;
isects.resize(count); isects.resize(count);
// find all intersections // find all intersections
@ -1681,7 +1681,7 @@ QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const
// flatten the sets of intersections // flatten the sets of intersections
for (int i=0; i<count; ++i) { for (int i=0; i<count; ++i) {
const QList<int> &current_isects = isects.at(i); const QVector<int> &current_isects = isects.at(i);
for (int j=0; j<current_isects.size(); ++j) { for (int j=0; j<current_isects.size(); ++j) {
int isect_j = current_isects.at(j); int isect_j = current_isects.at(j);
if (isect_j == i) if (isect_j == i)
@ -1709,7 +1709,7 @@ QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const
// Join the intersected subpaths as rewinded polygons // Join the intersected subpaths as rewinded polygons
for (int i=0; i<count; ++i) { for (int i=0; i<count; ++i) {
const QList<int> &subpath_list = isects[i]; const QVector<int> &subpath_list = isects[i];
if (!subpath_list.isEmpty()) { if (!subpath_list.isEmpty()) {
QPolygonF buildUp; QPolygonF buildUp;
for (int j=0; j<subpath_list.size(); ++j) { for (int j=0; j<subpath_list.size(); ++j) {

View File

@ -391,7 +391,7 @@ int QTextTablePrivate::findCellIndex(int fragment) const
{ {
QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment), QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment),
pieceTable->fragmentMap()); pieceTable->fragmentMap());
QList<int>::ConstIterator it = std::lower_bound(cells.constBegin(), cells.constEnd(), helper); const auto it = std::lower_bound(cells.constBegin(), cells.constEnd(), helper);
if ((it == cells.constEnd()) || (helper < *it)) if ((it == cells.constEnd()) || (helper < *it))
return -1; return -1;
return it - cells.constBegin(); return it - cells.constBegin();
@ -406,7 +406,7 @@ void QTextTablePrivate::fragmentAdded(QChar type, uint fragment)
Q_ASSERT(cells.indexOf(fragment) == -1); Q_ASSERT(cells.indexOf(fragment) == -1);
const uint pos = pieceTable->fragmentMap().position(fragment); const uint pos = pieceTable->fragmentMap().position(fragment);
QFragmentFindHelper helper(pos, pieceTable->fragmentMap()); QFragmentFindHelper helper(pos, pieceTable->fragmentMap());
QList<int>::Iterator it = std::lower_bound(cells.begin(), cells.end(), helper); auto it = std::lower_bound(cells.begin(), cells.end(), helper);
cells.insert(it, fragment); cells.insert(it, fragment);
if (!fragment_start || pos < pieceTable->fragmentMap().position(fragment_start)) if (!fragment_start || pos < pieceTable->fragmentMap().position(fragment_start))
fragment_start = fragment; fragment_start = fragment;
@ -616,7 +616,7 @@ QTextTableCell QTextTable::cellAt(int position) const
return QTextTableCell(); return QTextTableCell();
QFragmentFindHelper helper(position, map); QFragmentFindHelper helper(position, map);
QList<int>::ConstIterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); auto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper);
if (it != d->cells.begin()) if (it != d->cells.begin())
--it; --it;
@ -755,7 +755,7 @@ void QTextTable::insertColumns(int pos, int num)
QTextFormatCollection *c = p->formatCollection(); QTextFormatCollection *c = p->formatCollection();
p->beginEditBlock(); p->beginEditBlock();
QList<int> extendedSpans; QVector<int> extendedSpans;
for (int i = 0; i < d->nRows; ++i) { for (int i = 0; i < d->nRows; ++i) {
int cell; int cell;
if (i == d->nRows - 1 && pos == d->nCols) { if (i == d->nRows - 1 && pos == d->nCols) {
@ -890,7 +890,7 @@ void QTextTable::removeRows(int pos, int num)
p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition()); p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition());
QList<int> touchedCells; QVector<int> touchedCells;
for (int r = pos; r < pos + num; ++r) { for (int r = pos; r < pos + num; ++r) {
for (int c = 0; c < d->nCols; ++c) { for (int c = 0; c < d->nCols; ++c) {
int cell = d->grid[r*d->nCols + c]; int cell = d->grid[r*d->nCols + c];
@ -952,7 +952,7 @@ void QTextTable::removeColumns(int pos, int num)
p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition()); p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition());
QList<int> touchedCells; QVector<int> touchedCells;
for (int r = 0; r < d->nRows; ++r) { for (int r = 0; r < d->nRows; ++r) {
for (int c = pos; c < pos + num; ++c) { for (int c = pos; c < pos + num; ++c) {
int cell = d->grid[r*d->nCols + c]; int cell = d->grid[r*d->nCols + c];
@ -1046,7 +1046,7 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols)
// find the position at which to insert the contents of the merged cells // find the position at which to insert the contents of the merged cells
QFragmentFindHelper helper(origCellPosition, p->fragmentMap()); QFragmentFindHelper helper(origCellPosition, p->fragmentMap());
QList<int>::Iterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); const auto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end()); Q_ASSERT(it != d->cells.end());
Q_ASSERT(!(helper < *it)); Q_ASSERT(!(helper < *it));
Q_ASSERT(*it == cellFragment); Q_ASSERT(*it == cellFragment);
@ -1079,7 +1079,7 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols)
if (firstCellIndex == -1) { if (firstCellIndex == -1) {
QFragmentFindHelper helper(pos, p->fragmentMap()); QFragmentFindHelper helper(pos, p->fragmentMap());
QList<int>::Iterator it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); const auto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper);
Q_ASSERT(it != d->cells.end()); Q_ASSERT(it != d->cells.end());
Q_ASSERT(!(helper < *it)); Q_ASSERT(!(helper < *it));
Q_ASSERT(*it == fragment); Q_ASSERT(*it == fragment);

View File

@ -71,7 +71,7 @@ public:
int findCellIndex(int fragment) const; int findCellIndex(int fragment) const;
QList<int> cells; QVector<int> cells;
// symmetric to cells array and maps to indecs in grid, // symmetric to cells array and maps to indecs in grid,
// used for fast-lookup for row/column by fragment // used for fast-lookup for row/column by fragment
mutable QVector<int> cellIndices; mutable QVector<int> cellIndices;

View File

@ -187,8 +187,8 @@ public:
int columnSectionAnchor; int columnSectionAnchor;
int columnResizeTimerID; int columnResizeTimerID;
int rowResizeTimerID; int rowResizeTimerID;
QList<int> columnsToUpdate; QVector<int> columnsToUpdate;
QList<int> rowsToUpdate; QVector<int> rowsToUpdate;
QHeaderView *horizontalHeader; QHeaderView *horizontalHeader;
QHeaderView *verticalHeader; QHeaderView *verticalHeader;
QWidget *cornerWidget; QWidget *cornerWidget;

View File

@ -91,7 +91,7 @@ public:
QVariant userData; QVariant userData;
#ifndef QT_NO_SHORTCUT #ifndef QT_NO_SHORTCUT
int shortcutId; int shortcutId;
QList<int> alternateShortcutIds; QVector<int> alternateShortcutIds;
Qt::ShortcutContext shortcutContext; Qt::ShortcutContext shortcutContext;
uint autorepeat : 1; uint autorepeat : 1;
#endif #endif