QHeaderView: apply small optimization in recalcSectionStartPos()

The loop in recalcSectionStartPos() calls QVector<>::constEnd() after
every iteration which is not needed since the vector stays constant.
Therefore use the new for loop syntax from c++11 so constEnd() is only
called once which gives a small speedup, noticeable with large section
counts.

Change-Id: If318eec10c9ce234004a9922409fbdbc6409f2f8
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
This commit is contained in:
Christian Ehrlicher 2018-09-21 20:14:15 +02:00
parent 6d648961c6
commit 8bd0e6709f

View File

@ -3877,9 +3877,9 @@ void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle()
void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast) void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast)
{ {
int pixelpos = 0; int pixelpos = 0;
for (QVector<SectionItem>::const_iterator i = sectionItems.constBegin(); i != sectionItems.constEnd(); ++i) { for (const SectionItem &i : sectionItems) {
i->calculated_startpos = pixelpos; // write into const mutable i.calculated_startpos = pixelpos; // write into const mutable
pixelpos += i->size; pixelpos += i.size;
} }
sectionStartposRecalc = false; sectionStartposRecalc = false;
} }