diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-06-04 21:36:46 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-07 14:18:04 +0100 |
commit | 64db4861bfcacc8849e8452b73d5c940d97aefd0 (patch) | |
tree | c39991072737ea1253adf5affb321ca7f4923f79 /src/corelib/tools | |
parent | bf0b4f332a2f1ec9860c610d98cd27e483869bec (diff) |
Replace QArrayData::capacityReserved with a full flags field
Instead of stealing one bit from the alloc field, let's use a full
32-bit for the flags. The first flag to be in the field is the
CapacityReserved (even though the allocate() function will store some
others there, not relevant for now).
This is done in preparation for the need for more flags necessary
anyway.
Change-Id: I4c997d14743495e0d4558a6fb0a6042eb3d4975d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.h | 12 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 15 |
3 files changed, 12 insertions, 19 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 592faf39c3..ce6f138497 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -183,7 +183,7 @@ static QArrayData *reallocateData(QArrayData *header, size_t allocSize, uint opt { header = static_cast<QArrayData *>(::realloc(header, allocSize)); if (header) - header->capacityReserved = bool(options & QArrayData::CapacityReserved); + header->flags = options; return header; } @@ -219,7 +219,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, header->ref.atomic.storeRelaxed(1); header->size = 0; header->alloc = capacity; - header->capacityReserved = bool(options & CapacityReserved); + header->flags = options; header->offset = data - quintptr(header); } diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index c2da2767c3..9a3b53338c 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -49,9 +49,9 @@ QT_BEGIN_NAMESPACE struct Q_CORE_EXPORT QArrayData { QtPrivate::RefCount ref; + uint flags; int size; - uint alloc : 31; - uint capacityReserved : 1; + uint alloc; qptrdiff offset; // in bytes from beginning of header @@ -90,7 +90,7 @@ struct Q_CORE_EXPORT QArrayData size_t detachCapacity(size_t newSize) const { - if (capacityReserved && newSize < alloc) + if (flags & CapacityReserved && newSize < alloc) return alloc; return newSize; } @@ -98,7 +98,7 @@ struct Q_CORE_EXPORT QArrayData ArrayOptions detachFlags() const { ArrayOptions result; - if (capacityReserved) + if (flags & CapacityReserved) result |= CapacityReserved; return result; } @@ -106,7 +106,7 @@ struct Q_CORE_EXPORT QArrayData ArrayOptions cloneFlags() const { ArrayOptions result; - if (capacityReserved) + if (flags & CapacityReserved) result |= CapacityReserved; return result; } @@ -304,7 +304,7 @@ struct QArrayDataPointerRef }; #define Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ - { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ + { Q_REFCOUNT_INITIALIZE_STATIC, QArrayData::DefaultAllocationFlags, size, 0, offset } \ /**/ #define Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(type, size) \ diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 3220ba1463..d64673cc16 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -119,12 +119,7 @@ public: *this = QVector<T>(); return; } - realloc(d->size); - } - if (d->capacityReserved) { - // capacity reserved in a read only memory would be useless - // this checks avoid writing to such memory. - d->capacityReserved = 0; + realloc(d->size, QArrayData::ArrayOptions(d->flags)); } } @@ -376,10 +371,10 @@ inline QVector<T>::QVector(const QVector<T> &v) if (v.d->ref.ref()) { d = v.d; } else { - if (v.d->capacityReserved) { + if (v.d->flags & Data::CapacityReserved) { d = Data::allocate(v.d->alloc); Q_CHECK_PTR(d); - d->capacityReserved = true; + d->flags |= Data::CapacityReserved; } else { d = Data::allocate(v.d->size); Q_CHECK_PTR(d); @@ -412,7 +407,7 @@ void QVector<T>::reserve(int asize) if (asize > int(d->alloc)) realloc(asize); if (isDetached()) - d->capacityReserved = 1; + d->flags |= Data::CapacityReserved; Q_ASSERT(capacity() >= asize); } @@ -644,7 +639,6 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Arra Data::deallocate(x); QT_RETHROW; } - x->capacityReserved = d->capacityReserved; } else { Q_ASSERT(int(d->alloc) == aalloc); // resize, without changing allocation size Q_ASSERT(isDetached()); // can be done only on detached d @@ -723,7 +717,6 @@ void QVector<T>::realloc(int aalloc, QArrayData::ArrayOptions options) Data::deallocate(x); QT_RETHROW; } - x->capacityReserved = d->capacityReserved; Q_ASSERT(d != x); if (!d->ref.deref()) { |