QtCore: don't convert single characters to QString for QTextCodec::fromUnicode()

Use the fromUnicode(QChar *, int size) overload instead.

Saves 0.5KiB text size on Linux GCC 4.9 AMD64 release builds.

Change-Id: I1a1081e09bff4c2116288b8c2616e1bb7ee2bb42
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-10-10 10:38:29 +02:00
parent a6ddae873b
commit 2463b4452d
2 changed files with 5 additions and 3 deletions

View File

@ -632,8 +632,9 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result,
int startPos = result.size();
result.reserve(startPos + str.size() * 3 / 2);
const QChar *unicode = str.unicode();
for (i = 0; i < str.size(); ++i) {
uint ch = str.at(i).unicode();
uint ch = unicode[i].unicode();
if (ch == ';' || ch == ',' || ch == '=')
needsQuotes = true;
@ -687,7 +688,7 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result,
#ifndef QT_NO_TEXTCODEC
} else if (useCodec) {
// slow
result += codec->fromUnicode(str.at(i));
result += codec->fromUnicode(&unicode[i], 1);
#endif
} else {
result += (char)ch;

View File

@ -3013,7 +3013,8 @@ void QXmlStreamWriterPrivate::checkIfASCIICompatibleCodec()
#ifndef QT_NO_TEXTCODEC
Q_ASSERT(encoder);
// assumes ASCII-compatibility for all 8-bit encodings
const QByteArray bytes = encoder->fromUnicode(QStringLiteral(" "));
QChar space = QLatin1Char(' ');
const QByteArray bytes = encoder->fromUnicode(&space, 1);
isCodecASCIICompatible = (bytes.count() == 1);
#else
isCodecASCIICompatible = true;