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>bb10
parent
1018dba04f
commit
2ed048fa8d
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue