From a1be56a6dfeda49abd50d8065183da8a70d546dc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 19 Oct 2023 15:27:19 +0200 Subject: [PATCH] QCborStreamWriter: use (new) QUtf8::convertFromLatin1() to speed up append(QL1SV) Use the new function to convert into a QVLA instead of first converting to a QString and then to a QByteArray. One conversion and one buffer instead of two each. Change-Id: Ieaa24c8ef325797b5a89e8da0ca4310667c00fa7 Reviewed-by: Thiago Macieira (cherry picked from commit 4cc31901ea36dcb37efbaa316dde653ad49a5dbb) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/serialization/qcborstreamwriter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/corelib/serialization/qcborstreamwriter.cpp b/src/corelib/serialization/qcborstreamwriter.cpp index 08273763aa5..2f0de496542 100644 --- a/src/corelib/serialization/qcborstreamwriter.cpp +++ b/src/corelib/serialization/qcborstreamwriter.cpp @@ -7,9 +7,11 @@ #include #include +#include #include #include #include +#include QT_BEGIN_NAMESPACE @@ -439,8 +441,10 @@ void QCborStreamWriter::append(QLatin1StringView str) // it is plain US-ASCII appendTextString(str.latin1(), str.size()); } else { - // non-ASCII, so we need a pass-through UTF-16 - append(QString(str)); + // non-ASCII, convert: + QVarLengthArray utf8(str.size() * 2); // each L1 char gives at most two U8 units + const qsizetype written = QUtf8::convertFromLatin1(utf8.data(), str) - utf8.data(); + appendTextString(utf8.data(), written); } }