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 <edward.welbourne@qt.io>
This commit is contained in:
Marc Mutz 2022-12-09 23:50:02 +01:00
parent 8ecd81ae86
commit 45c096a543

View File

@ -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');
}
/*!