diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-05-08 22:18:14 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-11 10:47:26 +0200 |
commit | 2ed048fa8dd506a8e57292e49dadd37011354a83 (patch) | |
tree | 7031798c8bfbd045b5fa1ae76105a2f8a85115be | |
parent | 1018dba04ff6b2f018cbd1a22ae630daa473bfb4 (diff) |
QString: optimize insert() of a substring
The old code malloc()ed a buffer to hold a copy of the data if a
substring of *this was to be inserted. Instead, use a QVarLengthArray.
Pick-to: 5.15
Change-Id: Ia3b4d7509bff2375ec0da5c890ecff2e9f7f335c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/corelib/text/qstring.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index aa3f49a619..f07f25b8dd 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2578,11 +2578,8 @@ QString& QString::insert(int i, const QChar *unicode, int size) const std::less<const ushort*> less; if (!less(s, d.data()) && less(s, d.data() + d.size)) { // Part of me - take a copy - ushort *tmp = static_cast<ushort *>(::malloc(size * sizeof(QChar))); - Q_CHECK_PTR(tmp); - memcpy(tmp, s, size * sizeof(QChar)); - insert(i, reinterpret_cast<const QChar *>(tmp), size); - ::free(tmp); + const QVarLengthArray<ushort> copy(s, s + size); + insert(i, reinterpret_cast<const QChar *>(copy.data()), size); return *this; } |