summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-04 13:11:23 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-19 11:30:43 +0000
commitbbe65832f57709ac14bccfe0d5d06723f1397d1d (patch)
tree99bb9bd4eeb19a34a7045d77c647370784c13818 /src/corelib/tools
parentdb9a0befca2415574e3bef8a0e07cf3fef62361c (diff)
QString::vasprintf: avoid allocating memory for format text copied verbatim
... by using the new QUtf8::convertToUnicode() function in conjunction with QString::resize(). For this to be a clear optimization, resize() must be banned from shrinking capacity, which another patch will implement. Change-Id: I6394af95ef1aaae131e23a4227734eb76fa685cd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index b965e35175..7e8eb5e317 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -5867,6 +5867,14 @@ QString &QString::vsprintf(const char *cformat, va_list ap)
return *this = vasprintf(cformat, ap);
}
+static void append_utf8(QString &qs, const char *cs, int len)
+{
+ const int oldSize = qs.size();
+ qs.resize(oldSize + len);
+ const QChar *newEnd = QUtf8::convertToUnicode(qs.data() + oldSize, cs, len);
+ qs.resize(newEnd - qs.constData());
+}
+
static uint parse_flag_characters(const char * &c) Q_DECL_NOTHROW
{
uint flags = 0;
@@ -5929,7 +5937,7 @@ QString QString::vasprintf(const char *cformat, va_list ap)
const char *cb = c;
while (*c != '\0' && *c != '%')
c++;
- result.append(QString::fromUtf8(cb, (int)(c - cb)));
+ append_utf8(result, cb, int(c - cb));
if (*c == '\0')
break;