From 45c096a54363c2c2b013ef86f0646bef791501e8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 9 Dec 2022 23:50:02 +0100 Subject: [PATCH] QXmlStreamWriter: hold the indent in std::string, not QByteArray This means that, thanks to std::string's SSO, we won't allocate to hold the indent step string anymore, at least for non-pathological indents of up to 15-23 characters, depending on the particular std::string implementation. Task-number: QTBUG-103302 Change-Id: I63685619e86a3aa7bcfac41db84f64a78859bdb7 Reviewed-by: Edward Welbourne --- src/corelib/serialization/qxmlstream.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index 04b408f080..e03b1a2c67 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -2876,7 +2876,7 @@ public: uint hasIoError :1; uint hasEncodingError :1; uint autoFormatting :1; - QByteArray autoFormattingIndent; + std::string autoFormattingIndent; NamespaceDeclaration emptyNamespace; qsizetype lastNamespaceDeclaration; @@ -3236,13 +3236,14 @@ bool QXmlStreamWriter::autoFormatting() const void QXmlStreamWriter::setAutoFormattingIndent(int spacesOrTabs) { Q_D(QXmlStreamWriter); - d->autoFormattingIndent = QByteArray(qAbs(spacesOrTabs), spacesOrTabs >= 0 ? ' ' : '\t'); + d->autoFormattingIndent.assign(size_t(qAbs(spacesOrTabs)), spacesOrTabs >= 0 ? ' ' : '\t'); } int QXmlStreamWriter::autoFormattingIndent() const { Q_D(const QXmlStreamWriter); - return d->autoFormattingIndent.count(' ') - d->autoFormattingIndent.count('\t'); + const QLatin1StringView indent(d->autoFormattingIndent); + return indent.count(u' ') - indent.count(u'\t'); } /*!