summaryrefslogtreecommitdiff
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-12-08 16:10:06 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-01-19 11:55:23 +0000
commite3f230e7be445b9cabaf1c8556bb97994813e205 (patch)
tree93c6e6ec69e1d8236d12aa824667d258ad957e75 /src/corelib/serialization
parent2ae75c2e6a49e84aa10691520752e340a4855b79 (diff)
downloadqtbase-e3f230e7be445b9cabaf1c8556bb97994813e205.tar.gz
Optimize QXmlStreamWriterPrivate::doWriteToDevice(QLatin1StringView)
Use a stack buffer, and perform the recoding from L1 to U8 in chunks. Solves the L1 case of Task-number: QTBUG-109284 Pick-to: 6.5 Change-Id: Ia9ac7d8b27fd452d24d9e27f0575f9fc83b6dcbc Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qxmlstream.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp
index 48487fd83d..0b5843f032 100644
--- a/src/corelib/serialization/qxmlstream.cpp
+++ b/src/corelib/serialization/qxmlstream.cpp
@@ -3085,10 +3085,14 @@ void QXmlStreamWriterPrivate::doWriteToDevice(QUtf8StringView s)
void QXmlStreamWriterPrivate::doWriteToDevice(QLatin1StringView s)
{
- QByteArray utf8(s.size() * 2, Qt::Uninitialized);
- char *end = QUtf8::convertFromLatin1(utf8.data(), s);
- utf8.truncate(end - utf8.data());
- doWriteToDevice(QUtf8StringView{utf8});
+ constexpr qsizetype MaxChunkSize = 512;
+ char buffer [2 * MaxChunkSize];
+ while (!s.isEmpty()) {
+ const qsizetype chunkSize = std::min(s.size(), MaxChunkSize);
+ char *end = QUtf8::convertFromLatin1(buffer, s.first(chunkSize));
+ doWriteToDevice(QUtf8StringView{buffer, end});
+ s = s.sliced(chunkSize);
+ }
}
/*!