QDataStream: don't store the byteorder member in Qt 7

It's redundant with the noswap member: we swap if the stream byte order
is the opposite of the CPU's and don't swap if it is the same. That the
default is to swap is another reason why people should stop using
QDataStream (though CBOR also stores numbers in big-endian).

Change-Id: I50e2158aeade4256ad1dfffd17b29adc2b698ead
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Thiago Macieira 2024-02-10 12:37:59 -08:00
parent 6dfc92abe8
commit b18ba91c67
2 changed files with 12 additions and 3 deletions

View File

@ -476,11 +476,14 @@ void QDataStream::setStatus(Status status)
void QDataStream::setByteOrder(ByteOrder bo)
{
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
// accessed by inline byteOrder() prior to Qt 6.8
byteorder = bo;
#endif
if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
noswap = (byteorder == BigEndian);
noswap = (bo == BigEndian);
else
noswap = (byteorder == LittleEndian);
noswap = (bo == LittleEndian);
}

View File

@ -221,7 +221,9 @@ private:
bool noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
quint8 fpPrecision = QDataStream::DoublePrecision;
quint8 q_status = Ok;
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
ByteOrder byteorder = BigEndian;
#endif
int ver = Qt_DefaultCompiledVersion;
quint16 transactionDepth = 0;
@ -438,7 +440,11 @@ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
#endif // INLINE_SINCE 6.8
inline QDataStream::ByteOrder QDataStream::byteOrder() const
{ return byteorder; }
{
if constexpr (QSysInfo::ByteOrder == QSysInfo::BigEndian)
return noswap ? BigEndian : LittleEndian;
return noswap ? LittleEndian : BigEndian;
}
inline int QDataStream::version() const
{ return ver; }