summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorIvan Komissarov <ABBAPOH@gmail.com>2015-05-27 15:12:54 +0300
committerIvan Komissarov <ABBAPOH@gmail.com>2015-05-28 11:02:22 +0000
commitbccdb62340659cfdf4e0f8b53180fb73fda6ea39 (patch)
tree254e9786afcf093b53b7455397dedcaeaa4665f6 /src/widgets
parent22ecebcc72e418b6bf22562bd8a247261a7a4a37 (diff)
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>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index 66ff472724..bca315f80b 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -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());