From 33159f5e0f18a6d9f4ca015bfb9a2a53089d1dfa Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 10 Feb 2024 12:49:43 -0800 Subject: [PATCH] QDataStream: make the public-ish private members smaller in Qt 7 pahole says: class QScopedPointer d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ quint8 q_status; /* 19 1 */ enum ByteOrder byteorder; /* 20 4 */ int ver; /* 24 4 */ quint16 transactionDepth; /* 28 2 */ /* size: 32, cachelines: 1, members: 10 */ Which is unnecessary overhead. The previous commit took care of byteorder for Qt 7; this one reduces the size a bit more, to 16 bytes on 32-bit systems and 24 on 64-bit ones. After this, pahole says for the bootstrap library: class QScopedPointer d; /* 0 8 */ class QIODevice * dev; /* 8 8 */ bool owndev; /* 16 1 */ bool noswap; /* 17 1 */ quint8 fpPrecision; /* 18 1 */ quint8 q_status; /* 19 1 */ enum Version ver; /* 20 1 */ /* XXX 1 byte hole, try to pack */ quint16 transactionDepth; /* 22 2 */ /* size: 24, cachelines: 1, members: 9 */ Further packing isn't possible, because of the alignment at 64-bit for this class. Change-Id: I50e2158aeade4256ad1dfffd17b29b80237a8c5b Reviewed-by: Marc Mutz Reviewed-by: Qt CI Bot Reviewed-by: Ivan Solovev --- src/corelib/serialization/qdatastream.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index 36d8a618ff..d3932372fa 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -45,7 +45,7 @@ QDataStream &writeAssociativeMultiContainer(QDataStream &s, const Container &c); class Q_CORE_EXPORT QDataStream : public QIODeviceBase { public: - enum Version { + enum Version QT7_ONLY(: quint8) { Qt_1_0 = 1, Qt_2_0 = 2, Qt_2_1 = 3, @@ -98,7 +98,7 @@ public: LittleEndian = QSysInfo::LittleEndian }; - enum Status { + enum Status QT7_ONLY(: quint8) { Ok, ReadPastEnd, ReadCorruptData, @@ -106,7 +106,7 @@ public: SizeLimitExceeded, }; - enum FloatingPointPrecision { + enum FloatingPointPrecision QT7_ONLY(: quint8) { SinglePrecision, DoublePrecision }; @@ -223,8 +223,10 @@ private: quint8 q_status = Ok; #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) ByteOrder byteorder = BigEndian; -#endif int ver = Qt_DefaultCompiledVersion; +#else + Version ver = Qt_DefaultCompiledVersion; +#endif quint16 transactionDepth = 0; #if QT_CORE_REMOVED_SINCE(6, 7) @@ -450,7 +452,7 @@ inline int QDataStream::version() const { return ver; } inline void QDataStream::setVersion(int v) -{ ver = v; } +{ ver = Version(v); } qint64 QDataStream::readQSizeType(QDataStream &s) {