From 13f3346d34c007727f60f9ee73805bcc0aa1c04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 20 Feb 2012 16:11:31 +0100 Subject: QHeaderView - create a union to save some space. Beside saving some space it also ensures a bit faster vector operations (remove and insert memcpy) - and lower the risk for a cache-miss. (Many operations seems to be about 5-10% faster in the benchmark). Change-Id: If8109e2146c25f642015906375dfbb449706ce8e Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qheaderview_p.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index 4d1f4ba5a0..2c657221dd 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -287,8 +287,11 @@ public: struct SectionSpan { int size; - mutable int calculated_startpos; - mutable int tmpLogIdx; + 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 SectionSpan() : size(0), resizeMode(QHeaderView::Interactive) {} inline SectionSpan(int length, QHeaderView::ResizeMode mode) @@ -296,7 +299,6 @@ public: 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 << 1; out << (int)resizeMode; } inline void read(QDataStream &in) -- cgit v1.2.3