summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-07-12 12:44:01 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-07-14 06:54:16 +0000
commit5d935dca0c70618af519c5bef2e11b4a1ee03507 (patch)
treea4489321fe9ac7381ef5e2664f41f73a2f5438fd
parentaca0e367be9cdc3b48f09200f4eadbcfe5a574c8 (diff)
Remove (private) QString::expand(), port to (new) QString::resize(int, QChar)
We cannot really remove the function, since it's called from inline code (QCharRef::op=(QChar)), but we can schedule it for removal in Qt 6, and inline it into existing in-tree callers. Change-Id: I3499f101dcb5ae908726b3673bf3526a04408db6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qstring.cpp17
-rw-r--r--src/corelib/tools/qstring.h4
2 files changed, 9 insertions, 12 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9dc7136d2a..68d12d85af 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 793a859228..3dda382dd5 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