diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 9dc7136d2a1..68d12d85af1 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1789,17 +1789,12 @@ void QString::reallocData(uint alloc, bool grow) } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void QString::expand(int i) { - int sz = d->size; - resize(qMax(i + 1, sz)); - if (d->size - 1 > sz) { - ushort *n = d->data() + d->size - 1; - ushort *e = d->data() + sz; - while (n != e) - * --n = ' '; - } + resize(qMax(i + 1, d->size), QLatin1Char(' ')); } +#endif /*! \fn void QString::clear() @@ -1986,7 +1981,7 @@ QString &QString::insert(int i, QLatin1String str) int len = str.size(); if (Q_UNLIKELY(i > d->size)) - expand(i + len - 1); + resize(i + len, QLatin1Char(' ')); else resize(d->size + len); @@ -2019,7 +2014,7 @@ QString& QString::insert(int i, const QChar *unicode, int size) } if (Q_UNLIKELY(i > d->size)) - expand(i + size - 1); + resize(i + size, QLatin1Char(' ')); else resize(d->size + size); @@ -2042,7 +2037,7 @@ QString& QString::insert(int i, QChar ch) if (i < 0) return *this; if (Q_UNLIKELY(i > d->size)) - expand(i); + resize(i + 1, QLatin1Char(' ')); else resize(d->size + 1); ::memmove(d->data() + i + 1, d->data() + i, (d->size - i - 1) * sizeof(QChar)); diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 793a859228f..3dda382dd59 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -803,7 +803,9 @@ private: Data *d; void reallocData(uint alloc, bool grow = false); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void expand(int i); +#endif QString multiArg(int numArgs, const QString **args) const; static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, @@ -990,7 +992,7 @@ public: inline operator QChar() const { return i < s.d->size ? s.d->data()[i] : 0; } inline QCharRef &operator=(QChar c) - { if (i >= s.d->size) s.expand(i); else s.detach(); + { if (i >= s.d->size) s.resize(i + 1, QLatin1Char(' ')); else s.detach(); s.d->data()[i] = c.unicode(); return *this; } // An operator= for each QChar cast constructors