Improve QHeaderView::sectionsInserted performance

Old implementation had complexity O(oldSectionCount); replace it with
O(hiddenSectionCount) algorithm. This boosts performance in case of the
vertical headers for models with big row count.

Change-Id: I7bb02f5579ce83fbdecf5f8c3aa7dcc0ac60dd40
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
bb10
Ivan Komissarov 2015-05-27 15:12:54 +03:00
parent 22ecebcc72
commit bccdb62340
1 changed files with 7 additions and 7 deletions

View File

@ -1879,13 +1879,13 @@ void QHeaderView::sectionsInserted(const QModelIndex &parent,
// insert sections into hiddenSectionSize
QHash<int, int> newHiddenSectionSize; // from logical index to section size
for (int i = 0; i < logicalFirst; ++i)
if (isSectionHidden(i))
newHiddenSectionSize[i] = d->hiddenSectionSize[i];
for (int j = logicalLast + 1; j < d->sectionCount(); ++j)
if (isSectionHidden(j))
newHiddenSectionSize[j] = d->hiddenSectionSize[j - insertCount];
d->hiddenSectionSize = newHiddenSectionSize;
for (QHash<int, int>::const_iterator it = d->hiddenSectionSize.cbegin(),
end = d->hiddenSectionSize.cend(); it != end; ++it) {
const int oldIndex = it.key();
const int newIndex = (oldIndex < logicalFirst) ? oldIndex : oldIndex + insertCount;
newHiddenSectionSize[newIndex] = it.value();
}
d->hiddenSectionSize.swap(newHiddenSectionSize);
d->doDelayedResizeSections();
emit sectionCountChanged(oldCount, count());