QCborValue: avoid a double isAscii check

The QCborValue(QL1S) constructor checks if the parameter is ASCII.
If it's not, it converts it to a QString and stores as such.
However, the QString is checked *again* for being ASCII. We know
it isn't -- skip this recheck.

Change-Id: I7a4776759b2b14aab955cffebde6e3b64f8ed1d1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Giuseppe D'Angelo 2024-04-09 08:40:15 +02:00
parent 421e7621fa
commit 4256651047
2 changed files with 9 additions and 3 deletions

View File

@ -1065,6 +1065,12 @@ Q_NEVER_INLINE void QCborContainerPrivate::appendAsciiString(QStringView s)
qt_to_latin1_unchecked(l, s.utf16(), len);
}
void QCborContainerPrivate::appendNonAsciiString(QStringView s)
{
appendByteData(reinterpret_cast<const char *>(s.utf16()), s.size() * 2,
QCborValue::String, QtCbor::Element::StringIsUtf16);
}
QCborValue QCborContainerPrivate::extractAt_complex(Element e)
{
// create a new container for the returned value, containing the byte data

View File

@ -228,13 +228,14 @@ public:
void append(QLatin1StringView s)
{
if (!QtPrivate::isAscii(s))
return append(QString(s));
return appendNonAsciiString(QString(s));
// US-ASCII is a subset of UTF-8, so we can keep in 8-bit
appendByteData(s.latin1(), s.size(), QCborValue::String,
QtCbor::Element::StringIsAscii);
}
void appendAsciiString(QStringView s);
void appendNonAsciiString(QStringView s);
void append(const QString &s)
{
@ -246,8 +247,7 @@ public:
if (QtPrivate::isAscii(s))
appendAsciiString(s);
else
appendByteData(reinterpret_cast<const char *>(s.utf16()), s.size() * 2,
QCborValue::String, QtCbor::Element::StringIsUtf16);
appendNonAsciiString(s);
}
void append(const QCborValue &v)
{