Use QVector::reserve() all over the place.
Reduces internal memory fragmentation. The search criteria was: QVector::append(), QVector::push_back(), QVector::operator<<() and QVector::operator+=() calls inside for, do and while loops. Statements inside ifs and out of loops weren't considered. Change-Id: Ie5aaf3cdfac938994e6e5dfa5f51de501ed79a0c Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
29e88fd8f0
commit
20147fae60
|
|
@ -2128,6 +2128,7 @@ bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &pa
|
|||
// remove corresponding source intervals
|
||||
// ### if this proves to be slow, we can switch to single-row removal
|
||||
QVector<int> rows;
|
||||
rows.reserve(count);
|
||||
for (int i = row; i < row + count; ++i)
|
||||
rows.append(m->source_rows.at(i));
|
||||
std::sort(rows.begin(), rows.end());
|
||||
|
|
@ -2167,6 +2168,7 @@ bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelInd
|
|||
}
|
||||
// remove corresponding source intervals
|
||||
QVector<int> columns;
|
||||
columns.reserve(count);
|
||||
for (int i = column; i < column + count; ++i)
|
||||
columns.append(m->source_columns.at(i));
|
||||
|
||||
|
|
|
|||
|
|
@ -1219,6 +1219,7 @@ QVector<QPointF> static inline tcbToBezier(const TCBPoints &tcbPoints)
|
|||
{
|
||||
const int count = tcbPoints.count();
|
||||
QVector<QPointF> bezierPoints;
|
||||
bezierPoints.reserve(3 * (count - 1));
|
||||
|
||||
for (int i = 1; i < count; i++) {
|
||||
const qreal t_0 = tcbPoints.at(i - 1)._t;
|
||||
|
|
|
|||
|
|
@ -764,6 +764,7 @@ QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime,
|
|||
if (hasTransitions()) {
|
||||
QTimeZonePrivate::DataList plist = d->transitions(fromDateTime.toMSecsSinceEpoch(),
|
||||
toDateTime.toMSecsSinceEpoch());
|
||||
list.reserve(plist.count());
|
||||
foreach (const QTimeZonePrivate::Data &pdata, plist)
|
||||
list.append(d->toOffsetData(pdata));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -630,6 +630,7 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
|
|||
}
|
||||
|
||||
// Now for each transition time calculate our rule and save them
|
||||
m_tranTimes.reserve(tranList.count());
|
||||
foreach (const QTzTransition &tz_tran, tranList) {
|
||||
QTzTransitionTime tran;
|
||||
QTzTransitionRule rule;
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ void QPicturePaintEngine::drawPolygon(const QPointF *points, int numPoints, Poly
|
|||
int pos;
|
||||
|
||||
QPolygonF polygon;
|
||||
polygon.reserve(numPoints);
|
||||
for (int i=0; i<numPoints; ++i)
|
||||
polygon << points[i];
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,9 @@ static QRegion deviceRegion(const QRegion ®ion, QWindow *window)
|
|||
return region;
|
||||
|
||||
QVector<QRect> rects;
|
||||
foreach (QRect rect, region.rects())
|
||||
const QVector<QRect> regionRects = region.rects();
|
||||
rects.reserve(regionRects.count());
|
||||
foreach (const QRect &rect, regionRects)
|
||||
rects.append(deviceRect(rect, window));
|
||||
|
||||
QRegion deviceRegion;
|
||||
|
|
|
|||
|
|
@ -1381,7 +1381,9 @@ static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &pol
|
|||
path = transform.map(path);
|
||||
|
||||
QPolygonF result;
|
||||
for (int i = 0; i < path.elementCount(); ++i)
|
||||
const int elementCount = path.elementCount();
|
||||
result.reserve(elementCount);
|
||||
for (int i = 0; i < elementCount; ++i)
|
||||
result << path.elementAt(i);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -671,6 +671,7 @@ void QSslSocketPrivate::resetDefaultEllipticCurves()
|
|||
QVarLengthArray<EC_builtin_curve> builtinCurves(static_cast<int>(curveCount));
|
||||
|
||||
if (q_EC_get_builtin_curves(builtinCurves.data(), curveCount) == curveCount) {
|
||||
curves.reserve(int(curveCount));
|
||||
for (size_t i = 0; i < curveCount; ++i) {
|
||||
QSslEllipticCurve curve;
|
||||
curve.id = builtinCurves[int(i)].nid;
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
|
|||
sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr));
|
||||
if (!hasMediumIcon)
|
||||
sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr));
|
||||
|
||||
ret.reserve(sizes.size());
|
||||
foreach (QSize size, sizes) {
|
||||
// Protocol specifies ARGB32 format in network byte order
|
||||
QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32);
|
||||
|
|
|
|||
|
|
@ -206,10 +206,11 @@ void QFbScreen::generateRects()
|
|||
}
|
||||
#endif
|
||||
}
|
||||
foreach (const QRect &rect, remainingScreen.rects())
|
||||
const QVector<QRect> remainingScreenRects = remainingScreen.rects();
|
||||
mCachedRects.reserve(mCachedRects.count() + remainingScreenRects.count());
|
||||
foreach (const QRect &rect, remainingScreenRects)
|
||||
mCachedRects += QPair<QRect, int>(rect, -1);
|
||||
mIsUpToDate = true;
|
||||
return;
|
||||
}
|
||||
|
||||
QRegion QFbScreen::doRedraw()
|
||||
|
|
|
|||
|
|
@ -689,6 +689,7 @@ void QXcbDrag::handleEnter(QWindow *window, const xcb_client_message_event_t *ev
|
|||
length = xdnd_max_type;
|
||||
|
||||
xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
|
||||
xdnd_types.reserve(length);
|
||||
for (int i = 0; i < length; ++i)
|
||||
xdnd_types.append(atoms[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2688,7 +2688,9 @@ void QXcbWindow::setMask(const QRegion ®ion)
|
|||
} else {
|
||||
const int dpr = devicePixelRatio();
|
||||
QVector<xcb_rectangle_t> rects;
|
||||
foreach (const QRect &r, region.rects())
|
||||
const QVector<QRect> regionRects = region.rects();
|
||||
rects.reserve(regionRects.count());
|
||||
foreach (const QRect &r, regionRects)
|
||||
rects.push_back(qRectToXCBRectangle(mapLocalGeometryToNative(r, dpr)));
|
||||
xcb_shape_rectangles(connection()->xcb_connection(), XCB_SHAPE_SO_SET,
|
||||
XCB_SHAPE_SK_BOUNDING, XCB_CLIP_ORDERING_UNSORTED,
|
||||
|
|
|
|||
|
|
@ -267,6 +267,7 @@ void QPpdPrintDevice::loadInputSlots() const
|
|||
if (m_ppd) {
|
||||
ppd_option_t *inputSlots = ppdFindOption(m_ppd, "InputSlot");
|
||||
if (inputSlots) {
|
||||
m_inputSlots.reserve(inputSlots->num_choices);
|
||||
for (int i = 0; i < inputSlots->num_choices; ++i)
|
||||
m_inputSlots.append(QPrintUtils::ppdChoiceToInputSlot(inputSlots->choices[i]));
|
||||
}
|
||||
|
|
@ -307,6 +308,7 @@ void QPpdPrintDevice::loadOutputBins() const
|
|||
if (m_ppd) {
|
||||
ppd_option_t *outputBins = ppdFindOption(m_ppd, "OutputBin");
|
||||
if (outputBins) {
|
||||
m_outputBins.reserve(outputBins->num_choices);
|
||||
for (int i = 0; i < outputBins->num_choices; ++i)
|
||||
m_outputBins.append(QPrintUtils::ppdChoiceToOutputBin(outputBins->choices[i]));
|
||||
}
|
||||
|
|
@ -348,6 +350,7 @@ void QPpdPrintDevice::loadDuplexModes() const
|
|||
if (m_ppd) {
|
||||
ppd_option_t *duplexModes = ppdFindOption(m_ppd, "Duplex");
|
||||
if (duplexModes) {
|
||||
m_duplexModes.reserve(duplexModes->num_choices);
|
||||
for (int i = 0; i < duplexModes->num_choices; ++i)
|
||||
m_duplexModes.append(QPrintUtils::ppdChoiceToDuplexMode(duplexModes->choices[i].choice));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -751,6 +751,7 @@ void QWizardPrivate::init()
|
|||
|
||||
updateButtonLayout();
|
||||
|
||||
defaultPropertyTable.reserve(NFallbackDefaultProperties);
|
||||
for (uint i = 0; i < NFallbackDefaultProperties; ++i)
|
||||
defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className,
|
||||
fallbackProperties[i].property,
|
||||
|
|
|
|||
|
|
@ -751,6 +751,7 @@ static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph,
|
|||
|
||||
AnchorVertex *prev = before;
|
||||
QVector<AnchorData *> edges;
|
||||
edges.reserve(vertices.count() + 1);
|
||||
|
||||
const int numVertices = vertices.count();
|
||||
edges.reserve(numVertices + 1);
|
||||
|
|
|
|||
|
|
@ -2464,6 +2464,7 @@ QPolygonF QGraphicsView::mapToScene(const QRect &rect) const
|
|||
QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const
|
||||
{
|
||||
QPolygonF poly;
|
||||
poly.reserve(polygon.count());
|
||||
foreach (const QPoint &point, polygon)
|
||||
poly << mapToScene(point);
|
||||
return poly;
|
||||
|
|
@ -2559,6 +2560,7 @@ QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const
|
|||
QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const
|
||||
{
|
||||
QPolygon poly;
|
||||
poly.reserve(polygon.count());
|
||||
foreach (const QPointF &point, polygon)
|
||||
poly << mapFromScene(point);
|
||||
return poly;
|
||||
|
|
@ -2673,7 +2675,9 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects)
|
|||
// Extract and reset dirty scene rect info.
|
||||
QVector<QRect> dirtyViewportRects;
|
||||
const QVector<QRect> &dirtyRects = d->dirtyRegion.rects();
|
||||
for (int i = 0; i < dirtyRects.size(); ++i)
|
||||
const int dirtyRectsCount = dirtyRects.size();
|
||||
dirtyViewportRects.reserve(dirtyRectsCount + rects.count());
|
||||
for (int i = 0; i < dirtyRectsCount; ++i)
|
||||
dirtyViewportRects += dirtyRects.at(i);
|
||||
d->dirtyRegion = QRegion();
|
||||
d->dirtyBoundingRect = QRect();
|
||||
|
|
|
|||
|
|
@ -861,11 +861,15 @@ void QColumnView::setColumnWidths(const QList<int> &list)
|
|||
{
|
||||
Q_D(QColumnView);
|
||||
int i = 0;
|
||||
for (; (i < list.count() && i < d->columns.count()); ++i) {
|
||||
const int listCount = list.count();
|
||||
const int count = qMin(listCount, d->columns.count());
|
||||
for (; i < count; ++i) {
|
||||
d->columns.at(i)->resize(list.at(i), d->columns.at(i)->height());
|
||||
d->columnSizes[i] = list.at(i);
|
||||
}
|
||||
for (; i < list.count(); ++i)
|
||||
|
||||
d->columnSizes.reserve(listCount);
|
||||
for (; i < listCount; ++i)
|
||||
d->columnSizes.append(list.at(i));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,9 @@ void QMenuBarPrivate::updateGeometries()
|
|||
for(int j = 0; j < shortcutIndexMap.size(); ++j)
|
||||
q->releaseShortcut(shortcutIndexMap.value(j));
|
||||
shortcutIndexMap.resize(0); // faster than clear
|
||||
for(int i = 0; i < actions.count(); i++)
|
||||
const int actionsCount = actions.count();
|
||||
shortcutIndexMap.reserve(actionsCount);
|
||||
for (int i = 0; i < actionsCount; i++)
|
||||
shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text())));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue