From 62c673ccc6f81cee09a25f5acceec2768cea4672 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 11 Jun 2012 19:42:05 +0200 Subject: Add reference-count manipulation functions to QArrayData and hide ref The next change will stop using some values in the reference counter as settings from the data. Change-Id: I94df1fe643896373fac2f000fff55bc7708fc807 Reviewed-by: Simon Hausmann --- src/corelib/tools/qvector.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/corelib/tools/qvector.h') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index a596beedcf..d9512ee90e 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -89,7 +89,7 @@ public: explicit QVector(int size); QVector(int size, const T &t); inline QVector(const QVector &v); - inline ~QVector() { if (!d->ref.deref()) freeData(d); } + inline ~QVector() { if (!d->deref()) freeData(d); } QVector &operator=(const QVector &v); QVector(QVector &&other) noexcept : d(other.d) { other.d = Data::sharedNull(); } QVector &operator=(QVector &&other) noexcept @@ -114,17 +114,17 @@ public: void reserve(int size); inline void squeeze() { - if (d->size < int(d->alloc)) { + if (d->size < int(d->allocatedCapacity())) { if (!d->size) { *this = QVector(); return; } - realloc(d->size, QArrayData::ArrayOptions(d->flags)); + realloc(d->size, d->detachFlags()); } } inline void detach(); - inline bool isDetached() const { return !d->ref.isShared(); } + inline bool isDetached() const { return !d->isShared(); } inline bool isSharedWith(const QVector &other) const { return d == other.d; } @@ -365,7 +365,7 @@ void QVector::destruct(T *from, T *to) template inline QVector::QVector(const QVector &v) { - if (v.d->ref.ref()) { + if (v.d->ref()) { d = v.d; } else { if (v.d->flags & Data::CapacityReserved) { @@ -391,7 +391,7 @@ template void QVector::detach() { // ### check whether this is still required - if (d->ref.isStatic()) + if (d->isStatic()) return; if (d->needsDetach()) @@ -581,14 +581,14 @@ void QVector::realloc(int aalloc, QArrayData::ArrayOptions options) Q_ASSERT(aalloc >= d->size); Data *x = d; - const bool isShared = d->ref.isShared(); + const bool isShared = d->isShared(); QT_TRY { // allocate memory x = Data::allocate(aalloc, options); Q_CHECK_PTR(x); // aalloc is bigger then 0 so it is not [un]sharedEmpty - Q_ASSERT(!x->ref.isStatic()); + Q_ASSERT(!x->isStatic()); x->size = d->size; T *srcBegin = d->begin(); @@ -621,7 +621,7 @@ void QVector::realloc(int aalloc, QArrayData::ArrayOptions options) } Q_ASSERT(d != x); - if (!d->ref.deref()) { + if (!d->deref()) { if (!QTypeInfoQuery::isRelocatable || !aalloc || (isShared && QTypeInfo::isComplex)) { // data was copy constructed, we need to call destructors // or if !alloc we did nothing to the old 'd'. @@ -701,7 +701,7 @@ void QVector::removeLast() Q_ASSERT(!isEmpty()); Q_ASSERT(d->allocatedCapacity()); - if (d->ref.isShared()) + if (d->isShared()) detach(); --d->size; if (QTypeInfo::isComplex) -- cgit v1.2.3