QDataStream: make the public-ish private members smaller in Qt 7

pahole says:
  class QScopedPointer<QDataStreamPrivate> 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<QDataStreamPrivate> 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 <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
Thiago Macieira 2024-02-10 12:49:43 -08:00
parent b18ba91c67
commit 33159f5e0f
1 changed files with 7 additions and 5 deletions

View File

@ -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)
{