QHeaderView - create a union to save some space.
authorThorbjørn Lund Martsum <tmartsum@gmail.com>
Mon, 20 Feb 2012 15:11:31 +0000 (16:11 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 21 Feb 2012 11:52:00 +0000 (12:52 +0100)
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 <stephen.kelly@kdab.com>
src/widgets/itemviews/qheaderview_p.h

index 4d1f4ba..2c65722 100644 (file)
@@ -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)