diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-04-06 10:12:36 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-16 15:51:20 +0200 |
commit | 76d61af1e272628aa38f088ea10ec7076fae8b06 (patch) | |
tree | ac38b5f674920d59c4bec060ad438685a96ff9e0 /src/corelib/tools/qbytearray.h | |
parent | 3111e6d6fad99c3759628eb416bbb446b4f0a605 (diff) |
Make reallocData use QArrayData::AllocationOptions
Growth computations are deferred to QArrayData::allocate, except in the
case of realloc as that functionality is currently lacking in
QArrayData. Since that sits in library code, anyway, it can be changed
later to use a future QArrayData::reallocate.
As it is, reallocData is becoming a model for QArrayData::reallocate
and what it can offer to containers of POD/movable types.
Change-Id: I045483f729114be43e4818149d1be1b333bcbe13
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 648fe6a162..f8427f66a5 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -415,7 +415,7 @@ public: private: operator QNoImplicitBoolCast() const; Data *d; - void reallocData(uint alloc, bool grow = false); + void reallocData(uint alloc, Data::AllocationOptions options); void expand(int i); QByteArray nulTerminated() const; @@ -454,7 +454,7 @@ inline const char *QByteArray::data() const inline const char *QByteArray::constData() const { return d->data(); } inline void QByteArray::detach() -{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u); } +{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); } inline bool QByteArray::isDetached() const { return !d->ref.isShared(); } inline QByteArray::QByteArray(const QByteArray &a) : d(a.d) @@ -465,21 +465,20 @@ inline int QByteArray::capacity() const inline void QByteArray::reserve(int asize) { - if (d->ref.isShared() || uint(asize) + 1u > d->alloc) - reallocData(uint(asize) + 1u); - - if (!d->capacityReserved) { - // cannot set unconditionally, since d could be the shared_null/shared_empty (which is const) + if (d->ref.isShared() || uint(asize) + 1u > d->alloc) { + reallocData(uint(asize) + 1u, d->detachFlags() | Data::CapacityReserved); + } else { + // cannot set unconditionally, since d could be the shared_null or + // otherwise static d->capacityReserved = true; } } inline void QByteArray::squeeze() { - if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) - reallocData(uint(d->size) + 1u); - - if (d->capacityReserved) { + if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) { + reallocData(uint(d->size) + 1u, d->detachFlags() & ~Data::CapacityReserved); + } else { // cannot set unconditionally, since d could be shared_null or // otherwise static. d->capacityReserved = false; |