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.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/widgets/itemviews/qheaderview.cpp') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index c9a845fc7b..e0034d1298 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -80,6 +80,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionItem §io } #endif // QT_NO_DATASTREAM +static const int maxSizeSection = 1048575; // since section size is in a bitfield (uint 20). See qheaderview_p.h /*! \class QHeaderView @@ -884,7 +885,7 @@ void QHeaderView::swapSections(int first, int second) void QHeaderView::resizeSection(int logical, int size) { Q_D(QHeaderView); - if (logical < 0 || logical >= count() || size < 0) + if (logical < 0 || logical >= count() || size < 0 || size > maxSizeSection) return; if (isSectionHidden(logical)) { @@ -1567,7 +1568,7 @@ int QHeaderView::defaultSectionSize() const void QHeaderView::setDefaultSectionSize(int size) { Q_D(QHeaderView); - if (size < 0) + if (size < 0 || size > maxSizeSection) return; d->setDefaultSectionSize(size); } @@ -1602,7 +1603,7 @@ int QHeaderView::minimumSectionSize() const void QHeaderView::setMinimumSectionSize(int size) { Q_D(QHeaderView); - if (size < 0) + if (size < 0 || size > maxSizeSection) return; d->minimumSectionSize = size; } @@ -3549,7 +3550,7 @@ QHeaderView::ResizeMode QHeaderViewPrivate::headerSectionResizeMode(int visual) { if (visual < 0 || visual >= sectionItems.count()) return globalResizeMode; - return sectionItems.at(visual).resizeMode; + return static_cast(sectionItems.at(visual).resizeMode); } void QHeaderViewPrivate::setGlobalHeaderResizeMode(QHeaderView::ResizeMode mode) -- cgit v1.2.3