From 4be7c046b1792a97e6e3e5c9dd9e3f71ffb11529 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 26 Feb 2024 20:03:46 -0800 Subject: [PATCH] Bootstrap: remove QDataStream It was only used by the cmake_automoc_parser so it would write a 64-bit in big-endian format. So bypass QDataStream and write it native endianness. Change-Id: I01ec3c774d9943adb903fffd17b79c78e56db4cf Reviewed-by: Fabian Kosmale Reviewed-by: Thiago Macieira Reviewed-by: Alexey Edelev --- src/corelib/kernel/qmetatype.cpp | 3 ++- src/corelib/kernel/qmetatype.h | 16 +++++++++------- src/corelib/serialization/qdatastream.h | 2 +- src/corelib/text/qbytearray.cpp | 2 +- src/corelib/text/qstring.cpp | 2 +- src/tools/bootstrap/CMakeLists.txt | 1 - src/tools/cmake_automoc_parser/main.cpp | 12 +++--------- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index ebe79e0232f..3ccff5ae5f8 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -22,13 +22,14 @@ #endif #include "quuid.h" #include "qvariant.h" -#include "qdatastream.h" #if QT_CONFIG(regularexpression) # include "qregularexpression.h" #endif #ifndef QT_BOOTSTRAPPED +# include "qdatastream.h" + # include "qbitarray.h" # include "qurl.h" # include "qvariant.h" diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 5528c2f4599..9c1fdeecdd4 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -2368,19 +2368,21 @@ struct QDebugStreamOperatorForType template> struct QDataStreamOperatorForType +{ + static constexpr QMetaTypeInterface::DataStreamOutFn dataStreamOut = nullptr; + static constexpr QMetaTypeInterface::DataStreamInFn dataStreamIn = nullptr; +}; + +#ifndef QT_NO_DATASTREAM +template +struct QDataStreamOperatorForType { static void dataStreamOut(const QMetaTypeInterface *, QDataStream &ds, const void *a) { ds << *reinterpret_cast(a); } static void dataStreamIn(const QMetaTypeInterface *, QDataStream &ds, void *a) { ds >> *reinterpret_cast(a); } }; - -template -struct QDataStreamOperatorForType -{ - static constexpr QMetaTypeInterface::DataStreamOutFn dataStreamOut = nullptr; - static constexpr QMetaTypeInterface::DataStreamInFn dataStreamIn = nullptr; -}; +#endif // Performance optimization: // diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h index d3932372fa5..cf37df71d75 100644 --- a/src/corelib/serialization/qdatastream.h +++ b/src/corelib/serialization/qdatastream.h @@ -25,7 +25,7 @@ class QDataStream; class QIODevice; class QString; -#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) +#if !defined(QT_NO_DATASTREAM) class QDataStreamPrivate; namespace QtPrivate { class StreamStateSaver; diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index cacf8cbf63d..522ae475e6a 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3329,7 +3329,7 @@ void QByteArray::clear() d.clear(); } -#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) +#if !defined(QT_NO_DATASTREAM) /*! \relates QByteArray diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 38df9b6f4de..9bc41bd313b 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -9549,7 +9549,7 @@ QString &QString::setRawData(const QChar *unicode, qsizetype size) \sa toUcs4(), toStdWString(), toStdU16String() */ -#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) +#if !defined(QT_NO_DATASTREAM) /*! \fn QDataStream &operator<<(QDataStream &stream, const QString &string) \relates QString diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index 4c64cb51831..a3babd89aa8 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -51,7 +51,6 @@ qt_internal_extend_target(Bootstrap ../../corelib/serialization/qcborcommon.cpp ../../corelib/serialization/qcborstreamwriter.cpp ../../corelib/serialization/qcborvalue.cpp - ../../corelib/serialization/qdatastream.cpp ../../corelib/serialization/qjsonarray.cpp ../../corelib/serialization/qjsoncbor.cpp ../../corelib/serialization/qjsondocument.cpp diff --git a/src/tools/cmake_automoc_parser/main.cpp b/src/tools/cmake_automoc_parser/main.cpp index 86e10d48ad4..de484b184bb 100644 --- a/src/tools/cmake_automoc_parser/main.cpp +++ b/src/tools/cmake_automoc_parser/main.cpp @@ -185,11 +185,8 @@ static bool writeJsonFiles(const QList &fileList, const QString &fileLi } qint64 timestamp = std::numeric_limits::min(); - QByteArray timestampBuffer = timestampFile.readAll(); - if (timestampBuffer.size() == sizeof(timestamp)) { - QDataStream istream(×tampBuffer, QIODevice::ReadOnly); - istream >> timestamp; - } + if (timestampFile.size() == sizeof(timestamp)) + timestampFile.read(reinterpret_cast(×tamp), sizeof(timestamp)); // Check if any of the metatype json files produced by automoc is newer than the last file // processed by cmake_automoc parser @@ -215,11 +212,8 @@ static bool writeJsonFiles(const QList &fileList, const QString &fileLi textStream.flush(); // Update the timestamp according the newest json file timestamp. - timestampBuffer.clear(); - QDataStream ostream(×tampBuffer, QIODevice::WriteOnly); - ostream << timestamp; timestampFile.resize(0); - timestampFile.write(timestampBuffer); + timestampFile.write(reinterpret_cast(×tamp), sizeof(timestamp)); } return true; }