QDataStream: inline floatingPointPrecision()

There is a 2-byte padding in all architectures between the noswap member
and byteorder, because the latter requires a 32-bit alignment. So we can
use this space to store this little-used field and avoid one more reason
for QDataStreamPrivate.

Now:
  class QScopedPointer<QDataStreamPrivate> d;      /*     0     8 */
  class QIODevice *          dev;                  /*     8     8 */
  bool                       owndev;               /*    16     1 */
  bool                       noswap;               /*    17     1 */
  quint8                     fpPrecision;          /*    18     1 */
  /* XXX 1 byte hole, try to pack */
  enum ByteOrder             byteorder;            /*    20     4 */
  int                        ver;                  /*    24     4 */
  enum Status                q_status;             /*    28     4 */
  /* size: 32, cachelines: 1, members: 9 */

Change-Id: I50e2158aeade4256ad1dfffd17b29c2c5db02c12
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2024-02-10 13:02:03 -08:00
parent 566b726b84
commit 4aa0eab263
3 changed files with 11 additions and 12 deletions

View File

@ -406,16 +406,14 @@ bool QDataStream::atEnd() const
}
/*!
\fn QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
Returns the floating point precision of the data stream.
\since 4.6
\sa FloatingPointPrecision, setFloatingPointPrecision()
*/
QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
{
return d ? d->floatingPointPrecision : QDataStream::DoublePrecision;
}
/*!
Sets the floating point precision of the data stream to \a precision. If the floating point precision is
@ -439,9 +437,7 @@ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
*/
void QDataStream::setFloatingPointPrecision(QDataStream::FloatingPointPrecision precision)
{
if (!d)
d.reset(new QDataStreamPrivate());
d->floatingPointPrecision = precision;
fpPrecision = precision;
}
/*!

View File

@ -127,6 +127,7 @@ public:
void setStatus(Status status);
void resetStatus();
QT_CORE_INLINE_SINCE(6, 8)
FloatingPointPrecision floatingPointPrecision() const;
void setFloatingPointPrecision(FloatingPointPrecision precision);
@ -218,6 +219,7 @@ private:
QIODevice *dev;
bool owndev;
bool noswap;
quint8 fpPrecision = QDataStream::DoublePrecision;
ByteOrder byteorder;
int ver;
Status q_status;
@ -426,6 +428,11 @@ QDataStream::Status QDataStream::status() const
{
return q_status;
}
QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
{
return FloatingPointPrecision(fpPrecision);
}
#endif // INLINE_SINCE 6.8
inline QDataStream::ByteOrder QDataStream::byteOrder() const

View File

@ -24,11 +24,7 @@ QT_BEGIN_NAMESPACE
class QDataStreamPrivate
{
public:
QDataStreamPrivate() : floatingPointPrecision(QDataStream::DoublePrecision),
transactionDepth(0) { }
QDataStream::FloatingPointPrecision floatingPointPrecision;
int transactionDepth;
int transactionDepth = 0;
};
#endif