From e3f230e7be445b9cabaf1c8556bb97994813e205 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 8 Dec 2022 16:10:06 +0100 Subject: [PATCH] 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 Reviewed-by: Fabian Kosmale --- src/corelib/serialization/qxmlstream.cpp | 12 ++++++++---- 1 file 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); + } } /*!