summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qheaderview_p.h
diff options
context:
space:
mode:
authorThorbjørn Lund Martsum <tmartsum@gmail.com>2011-12-29 08:59:37 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-15 18:17:01 +0100
commitb800d8b94a7861ecf8853621f6556fca186fb5b7 (patch)
tree78585f97c187a0bdc178ffe799cbdf50165d3a18 /src/widgets/itemviews/qheaderview_p.h
parent656dff47a6f2c5e53c1bb2e54bf21e053c82c32a (diff)
QHeaderView::moveSection performance boost
The patch also speeds up swapSections and hideSection a lot. It work by eliminating the Span. (That is forcing each 'Span' to have exactly one element) That saves a lot of loops since we can often lookup info fast - and/or change it fast. Since it is often a complexity change, it is difficult to put %-increase on. (The most used linear function is recalcSectionStartPos() - and it has a very low constant) However comparing with the new benchmark (2500 rows) swapSection, showHideSection and moveSection are about 20-40 factors faster. (Yes, it is a lot faster!) In the benchmark moveSection is about 300 factors faster. Beside being a far better model it is also far more simple. This fix partly solves: Task-number: QTBUG-19092 Change-Id: I8deeb9315276d15c68e8a27d5dcb8e0c0badf367 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qheaderview_p.h')
-rw-r--r--src/widgets/itemviews/qheaderview_p.h35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h
index e26c4a6475..9d7d97f582 100644
--- a/src/widgets/itemviews/qheaderview_p.h
+++ b/src/widgets/itemviews/qheaderview_p.h
@@ -97,7 +97,8 @@ public:
lastSectionSize(0),
sectionIndicatorOffset(0),
sectionIndicator(0),
- globalResizeMode(QHeaderView::Interactive)
+ globalResizeMode(QHeaderView::Interactive),
+ sectionStartposRecalc(true)
{}
@@ -281,22 +282,24 @@ public:
QLabel *sectionIndicator;
QHeaderView::ResizeMode globalResizeMode;
QList<QPersistentModelIndex> persistentHiddenSections;
-
+ mutable bool sectionStartposRecalc;
// header section spans
struct SectionSpan {
int size;
- int count;
+ mutable int calculated_startpos;
QHeaderView::ResizeMode resizeMode;
- inline SectionSpan() : size(0), count(0), resizeMode(QHeaderView::Interactive) {}
- inline SectionSpan(int length, int sections, QHeaderView::ResizeMode mode)
- : size(length), count(sections), resizeMode(mode) {}
- inline int sectionSize() const { return (count > 0 ? size / count : 0); }
+ inline SectionSpan() : size(0), resizeMode(QHeaderView::Interactive) {}
+ inline SectionSpan(int length, QHeaderView::ResizeMode mode)
+ : size(length), calculated_startpos(-1), resizeMode(mode) {}
+ inline int sectionSize() const { return size; }
+ inline int calculatedEndPos() const { return calculated_startpos + size; }
#ifndef QT_NO_DATASTREAM
+ int tmpDataStreamSectionCount;
inline void write(QDataStream &out) const
- { out << size; out << count; out << (int)resizeMode; }
+ { out << size; out << 1; out << (int)resizeMode; }
inline void read(QDataStream &in)
- { in >> size; in >> count; int m; in >> m; resizeMode = (QHeaderView::ResizeMode)m; }
+ { in >> size; in >> tmpDataStreamSectionCount; int m; in >> m; resizeMode = (QHeaderView::ResizeMode)m; }
#endif
};
@@ -306,12 +309,10 @@ public:
void removeSectionsFromSpans(int start, int end);
void resizeSectionSpan(int visualIndex, int oldSize, int newSize);
void setDefaultSectionSize(int size);
+ void recalcSectionStartPos() const; // not really const
inline int headerSectionCount() const { // for debugging
- int count = 0;
- for (int i = 0; i < sectionSpans.count(); ++i)
- count += sectionSpans.at(i).count;
- return count;
+ return sectionSpans.count();
}
inline int headerLength() const { // for debugging
@@ -329,12 +330,8 @@ public:
}
inline int sectionSpanIndex(int visual) const {
- int section_start = 0;
- for (int i = 0; i < sectionSpans.count(); ++i) {
- int section_end = section_start + sectionSpans.at(i).count - 1;
- if (visual >= section_start && visual <= section_end)
- return i;
- section_start = section_end + 1;
+ if (visual < sectionSpans.count() && visual >= 0) {
+ return visual;
}
return -1;
}