summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-06-04 22:04:13 +0200
committerLars Knoll <lars.knoll@qt.io>2019-12-07 14:18:12 +0100
commit8fb45ae5b8b8ad276aeb9bc9e40f351f47523087 (patch)
treed6c3c40b59b9650f5ea6815afa06bac3cec78897 /src/corelib/text/qstring.h
parent64db4861bfcacc8849e8452b73d5c940d97aefd0 (diff)
Introduce QArrayData::allocatedCapacity() and use it instead of d->alloc
In almost all cases, use d->allocatedCapacity() or d->constAllocatedCapacity() instead of d->alloc, since they do the same thing (right now). In the future, the functions will be changed. There is a separate const version because most const code should not need to know the allocation size -- only mutating code should need to know that There are a few cases where d->alloc was replaced with a better alternative, like d->size. The one case that remains in the code will be replaced by a different test when it's available. Change-Id: I48135469db4caf150f82df93fff42d2309b23719 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.h')
-rw-r--r--src/corelib/text/qstring.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 630a33c4ae..4d853bfc72 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -274,7 +274,7 @@ public:
void truncate(int pos);
void chop(int n);
- int capacity() const;
+ inline int capacity() const;
inline void reserve(int size);
inline void squeeze();
@@ -542,7 +542,7 @@ public:
inline QString &prepend(QLatin1String s) { return insert(0, s); }
inline QString &operator+=(QChar c) {
- if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
+ if (d->ref.isShared() || d->size + 1 > capacity())
reallocData(uint(d->size) + 2u, true);
d->data()[d->size++] = c.unicode();
d->data()[d->size] = '\0';
@@ -1049,7 +1049,7 @@ inline void QString::clear()
inline QString::QString(const QString &other) noexcept : d(other.d)
{ Q_ASSERT(&other != this); d->ref.ref(); }
inline int QString::capacity() const
-{ return d->alloc ? d->alloc - 1 : 0; }
+{ int realCapacity = d->constAllocatedCapacity(); return realCapacity ? realCapacity - 1 : 0; }
inline QString &QString::setNum(short n, int base)
{ return setNum(qlonglong(n), base); }
inline QString &QString::setNum(ushort n, int base)
@@ -1263,8 +1263,8 @@ inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); }
inline void QString::reserve(int asize)
{
- if (d->ref.isShared() || uint(asize) >= d->alloc)
- reallocData(qMax(asize, d->size) + 1u);
+ if (d->ref.isShared() || asize >= capacity())
+ reallocData(qMax(asize, size()) + 1u);
// we're not shared anymore, for sure
d->flags |= Data::CapacityReserved;
@@ -1272,7 +1272,7 @@ inline void QString::reserve(int asize)
inline void QString::squeeze()
{
- if (d->ref.isShared() || uint(d->size) + 1u < d->alloc)
+ if (d->ref.isShared() || d->size < capacity())
reallocData(uint(d->size) + 1u);
// we're not shared anymore, for sure