From f633bc7f7fb72ba261b46e979603376f0016c085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Martsum?= Date: Wed, 7 Aug 2013 08:15:58 +0200 Subject: QHeaderView - reduce memory usage Though the worst case memory usage was improved in b800d8b94a7861ecf8853621f6556fca186fb5b7 the best case usage changed. Since best case is the same as worst case in Qt5, we should use as little as possible, which this patch ensures. We reduce the memory usage from 3 to 2 ints per section - which is half of worst case in Qt4. There seems to be no bigger cost in performance doing that. The recalcSectionStartPos is still very fast. This patch limits the maximum section size to (2^20) ~ 1.000.000 pixels. This alleviates Task-number: QTBUG-32325 Change-Id: I9b7530030a31b4e35cf1ca9e32c6b936f5ea9790 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qheaderview_p.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/widgets/itemviews/qheaderview_p.h') diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index c56e0d6196..2bbd21a942 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -296,23 +296,27 @@ public: // header sections struct SectionItem { - int size; + uint size : 20; + uint reservedForIsHidden : 1; + uint resizeMode : 5; // (holding QHeaderView::ResizeMode) + uint currentlyUnusedPadding : 6; + union { // This union is made in order to save space and ensure good vector performance (on remove) mutable int calculated_startpos; // <- this is the primary used member. mutable int tmpLogIdx; // When one of these 'tmp'-members has been used we call int tmpDataStreamSectionCount; // recalcSectionStartPos() or set sectionStartposRecalc to true }; // to ensure that calculated_startpos will be calculated afterwards. - QHeaderView::ResizeMode resizeMode; + inline SectionItem() : size(0), resizeMode(QHeaderView::Interactive) {} inline SectionItem(int length, QHeaderView::ResizeMode mode) - : size(length), calculated_startpos(-1), resizeMode(mode) {} + : size(length), resizeMode(mode), calculated_startpos(-1) {} inline int sectionSize() const { return size; } inline int calculatedEndPos() const { return calculated_startpos + size; } #ifndef QT_NO_DATASTREAM inline void write(QDataStream &out) const - { out << size; out << 1; out << (int)resizeMode; } + { out << static_cast(size); out << 1; out << (int)resizeMode; } inline void read(QDataStream &in) - { in >> size; in >> tmpDataStreamSectionCount; int m; in >> m; resizeMode = (QHeaderView::ResizeMode)m; } + { int m; in >> m; size = m; in >> tmpDataStreamSectionCount; in >> m; resizeMode = m; } #endif }; -- cgit v1.2.3