From f6591e6638d2ea785995576bd1da659d5cf7c99c Mon Sep 17 00:00:00 2001 From: Magdalena Stojek Date: Fri, 11 Apr 2025 10:14:49 +0200 Subject: [PATCH] Refactor QXmlStreamWriterPrivate constructor to modernize initialization Apply NSDMI and move initializations to the constructor initializer list Fixes: QTBUG-135897 Pick-to: 6.8 Change-Id: I7adff41fa006669677df457704d20c02f1af7197 Reviewed-by: Ivan Solovev (cherry picked from commit 3265f409394e821605cfd1888a26f7fbdd4ba682) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/serialization/qxmlstream.cpp | 30 ++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index a01e98469de..7e14b098de9 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -2938,8 +2938,8 @@ public: bool finishStartElement(bool contents = true); void writeStartElement(QAnyStringView namespaceUri, QAnyStringView name, StartElementOption option = StartElementOption::KeepEverything); - QIODevice *device; - QString *stringDevice; + QIODevice *device = nullptr; + QString *stringDevice = nullptr; uint deleteDevice :1; uint inStartElement :1; uint inEmptyElement :1; @@ -2950,15 +2950,15 @@ public: uint autoFormatting :1; uint didWriteStartDocument :1; uint didWriteAnyToken :1; - std::string autoFormattingIndent; + std::string autoFormattingIndent = std::string(4, ' '); NamespaceDeclaration emptyNamespace; - qsizetype lastNamespaceDeclaration; + qsizetype lastNamespaceDeclaration = 1; NamespaceDeclaration &addExtraNamespace(QAnyStringView namespaceUri, QAnyStringView prefix); NamespaceDeclaration &findNamespace(QAnyStringView namespaceUri, bool writeDeclaration = false, bool noDefault = false); void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration); - int namespacePrefixCount; + int namespacePrefixCount = 0; void indent(int level); private: @@ -2969,22 +2969,12 @@ private: QXmlStreamWriterPrivate::QXmlStreamWriterPrivate(QXmlStreamWriter *q) - : autoFormattingIndent(4, ' ') + : q_ptr(q), deleteDevice(false), inStartElement(false), + inEmptyElement(false), lastWasStartElement(false), + wroteSomething(false), hasIoError(false), + hasEncodingError(false), autoFormatting(false), + didWriteStartDocument(false), didWriteAnyToken(false) { - q_ptr = q; - device = nullptr; - stringDevice = nullptr; - deleteDevice = false; - inStartElement = inEmptyElement = false; - wroteSomething = false; - hasIoError = false; - hasEncodingError = false; - lastWasStartElement = false; - lastNamespaceDeclaration = 1; - autoFormatting = false; - namespacePrefixCount = 0; - didWriteStartDocument = false; - didWriteAnyToken = false; } void QXmlStreamWriterPrivate::write(QAnyStringView s)