diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-02-23 07:43:30 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-23 14:57:06 +0100 |
commit | c951908bc201afa59402967d50fa926212845fae (patch) | |
tree | ee27aa3fca4ace7c3dfe63c7bcbae06e9c0cdc1c | |
parent | 949b7452e0d2402a3ba046a5ba1fe043b670baaa (diff) |
QString: add from{Ascii,Latin1,Utf8,Local8Bit() overloads for QByteArray
One of the more frequent uses for QByteArray::operator const char*()
is in passing a QByteArray to QString::fromLatin1().
But this is highly inefficient, since the bytearray already knows
its size, but since its demoted to a const char* in passing to
fromLatin1(), it forces the latter to call strlen() _again_.
The solution, then, is to add overloads for QByteArray that
pass the array's .size() as a second argument to the two-arg
fromLatin1() version.
Change-Id: I5ea1ad3c96d9e64167be53c0c418c7b7dba51f68
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/corelib/tools/qstring.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index f1bad5c028..12a5acb689 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -417,6 +417,10 @@ public: { return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size); } + static inline QString fromAscii(const QByteArray &str) { return fromAscii(str.data(), str.size()); } + static inline QString fromLatin1(const QByteArray &str) { return fromLatin1(str.data(), str.size()); } + static inline QString fromUtf8(const QByteArray &str) { return fromUtf8(str.data(), str.size()); } + static inline QString fromLocal8Bit(const QByteArray &str) { return fromLocal8Bit(str.data(), str.size()); } static QString fromUtf16(const ushort *, int size = -1); static QString fromUcs4(const uint *, int size = -1); static QString fromRawData(const QChar *, int size); |