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 <thiago.macieira@intel.com> (cherry picked from commit 4cc31901ea36dcb37efbaa316dde653ad49a5dbb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
516cae81df
commit
a1be56a6df
@ -7,9 +7,11 @@
|
||||
#include <private/qcborcommon_p.h>
|
||||
|
||||
#include <private/qnumeric_p.h>
|
||||
#include <private/qstringconverter_p.h>
|
||||
#include <qbuffer.h>
|
||||
#include <qdebug.h>
|
||||
#include <qstack.h>
|
||||
#include <qvarlengtharray.h>
|
||||
|
||||
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<char> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user