diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-10-10 20:02:15 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-13 09:30:01 +0100 |
commit | 8892e3d0fc8258975f27aa90bef741fb4254ce7e (patch) | |
tree | ceb00ffb5bdd8806f3f6cd56e88777a0f605cd69 /src/corelib/tools/qstring.cpp | |
parent | b0afad8f0b6a3be7ab3a23e063b0201cd68ada95 (diff) |
Improve the Latin1 conversion in QString a little
First, use Qt::Uninitialized, since we're about to overwrite the memory
anyway with the new Latin 1 string.
Second, move the actual body of the conversion to a static void
function, which seems to improve code generation a little and, of
course, paves the way for the in-place conversion.
Change-Id: Iaed99ba1e52facad676510aa98443223e188d70a
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a94b18b5d3..1b07e31c89 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -3946,13 +3946,9 @@ static inline __m128i mergeQuestionMarks(__m128i chunk) } #endif -static QByteArray toLatin1_helper(const QChar *data, int length) +static void toLatin1_helper(uchar *dst, const ushort *src, int length) { - QByteArray ba; if (length) { - ba.resize(length); - const ushort *src = reinterpret_cast<const ushort *>(data); - uchar *dst = (uchar*) ba.data(); #if defined(__SSE2__) if (length >= 16) { const int chunkCount = length >> 4; // divided by 16 @@ -4003,7 +3999,6 @@ static QByteArray toLatin1_helper(const QChar *data, int length) ++src; } } - return ba; } QByteArray QString::toLatin1_helper(const QString &string) @@ -4016,7 +4011,13 @@ QByteArray QString::toLatin1_helper(const QString &string) QByteArray QString::toLatin1_helper(const QChar *data, int length) { - return QT_PREPEND_NAMESPACE(toLatin1_helper)(data, length); + QByteArray ba(length, Qt::Uninitialized); + + // since we own the only copy, we're going to const_cast the constData; + // that avoids an unnecessary call to detach() and expansion code that will never get used + QT_PREPEND_NAMESPACE(toLatin1_helper)(reinterpret_cast<uchar *>(const_cast<char *>(ba.constData())), + reinterpret_cast<const ushort *>(data), length); + return ba; } /*! |