summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-04-04 15:36:09 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-16 15:50:53 +0200
commit2ac4c463afdb8a62b0abb8ba444f34ca50e8979c (patch)
tree56be42941a0221e1aa9d325fb7d7d5ac0557873e /src/corelib/tools/qbytearray.h
parent77fd8fd9977b987c99acba6417ac369a9975d989 (diff)
Make QByteArray and QString keep track of terminating null
In conceptual terms, this change increments the Data::alloc member by one for all strings allocated and maintained by these classes. Instances initialized with fromRawData retain 0 as the member value, so they are treated as immutable. This brings QByteArray and QString closer to QVector, making it possible for them to reference and share the same data in memory, in the future. It also brings them closer to QArrayData. In practical terms all comparisons to the alloc member were changed to take into account that it also tracks the terminating null character. Aside from the increment in the alloc member, there should be no user visible changes. Change-Id: I618f49022a9b1845754500c8f8706c72a68b9c7d Reviewed-by: João Abecasis <joao.abecasis@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r--src/corelib/tools/qbytearray.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 287245182a..b811a0c3e5 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -452,11 +452,11 @@ inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
{ d->ref.ref(); }
inline int QByteArray::capacity() const
-{ return d->alloc; }
+{ return d->alloc ? d->alloc - 1 : 0; }
inline void QByteArray::reserve(int asize)
{
- if (d->ref.isShared() || asize > int(d->alloc))
+ if (d->ref.isShared() || uint(asize) + 1u > d->alloc)
reallocData(uint(asize) + 1u);
if (!d->capacityReserved) {
@@ -467,7 +467,7 @@ inline void QByteArray::reserve(int asize)
inline void QByteArray::squeeze()
{
- if (d->ref.isShared() || d->size < int(d->alloc))
+ if (d->ref.isShared() || uint(d->size) + 1u < d->alloc)
reallocData(uint(d->size) + 1u);
if (d->capacityReserved) {