diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-12-16 17:22:45 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-04 23:37:58 +0100 |
commit | 7fadc3ce322706ed6c36ad907e83fed1992b490e (patch) | |
tree | 4f8fcd91d2459841d1af4916e438da9a9d934a89 /src/corelib/tools | |
parent | 7d16ea40331dc4480af823288e6ed3ca58a677d8 (diff) |
Get rid of assignment operators in RefCount
, and make it strictly a POD struct.
Since this operator was only being used to set the initial (owned) value
of the reference count, the name of the function introduced here to
replace it makes that use case explicit.
Change-Id: I2feadd2ac35dcb75ca211471baf5044a5f57cd62
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 16 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlist.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qmap.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qrefcount.h | 6 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 16 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 8 |
9 files changed, 28 insertions, 30 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 168249c074..e3a6bad7c5 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -69,7 +69,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1) & ~(alignment - 1); - header->ref = 1; + header->ref.initializeOwned(); header->size = 0; header->alloc = capacity; header->capacityReserved = reserve; diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index ed3f31fc43..f959effb43 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -576,7 +576,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) d.take(); // realloc was successful d.reset(p); } - d->ref = 1; + d->ref.initializeOwned(); d->size = len; d->alloc = len; d->capacityReserved = false; @@ -1304,7 +1304,7 @@ QByteArray::QByteArray(const char *str) int len = qstrlen(str); d = static_cast<Data *>(qMalloc(sizeof(Data) + len + 1)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = len; d->alloc = len; d->capacityReserved = false; @@ -1333,7 +1333,7 @@ QByteArray::QByteArray(const char *data, int size) } else { d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = size; d->capacityReserved = false; @@ -1357,7 +1357,7 @@ QByteArray::QByteArray(int size, char ch) } else { d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = size; d->capacityReserved = false; @@ -1377,7 +1377,7 @@ QByteArray::QByteArray(int size, Qt::Initialization) { d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = size; d->capacityReserved = false; @@ -1424,7 +1424,7 @@ void QByteArray::resize(int size) // Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(x); - x->ref = 1; + x->ref.initializeOwned(); x->size = size; x->alloc = size; x->capacityReserved = false; @@ -1466,7 +1466,7 @@ void QByteArray::realloc(int alloc) if (d->ref != 1 || d->offset) { Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + alloc + 1)); Q_CHECK_PTR(x); - x->ref = 1; + x->ref.initializeOwned(); x->size = qMin(alloc, d->size); x->alloc = alloc; x->capacityReserved = d->capacityReserved; @@ -3887,7 +3887,7 @@ QByteArray QByteArray::fromRawData(const char *data, int size) } else { x = static_cast<Data *>(qMalloc(sizeof(Data) + 1)); Q_CHECK_PTR(x); - x->ref = 1; + x->ref.initializeOwned(); x->size = size; x->alloc = 0; x->capacityReserved = false; diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index afb5ebe951..48a446cad6 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -196,7 +196,7 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), d = new QHashData; d->fakeNext = 0; d->buckets = 0; - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->nodeSize = nodeSize; d->userNumBits = userNumBits; diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 36cbc68eb8..55d229d351 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -253,7 +253,7 @@ void QLinkedList<T>::detach_helper() { union { QLinkedListData *d; Node *e; } x; x.d = new QLinkedListData; - x.d->ref = 1; + x.d->ref.initializeOwned(); x.d->size = d->size; x.d->sharable = true; Node *original = e->n; diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 94be78ea21..8ef5fadb73 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -85,7 +85,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num) Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + alloc * sizeof(void *))); Q_CHECK_PTR(t); - t->ref = 1; + t->ref.initializeOwned(); t->sharable = true; t->alloc = alloc; // The space reservation algorithm's optimization is biased towards appending: @@ -127,7 +127,7 @@ QListData::Data *QListData::detach(int alloc) Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + alloc * sizeof(void *))); Q_CHECK_PTR(t); - t->ref = 1; + t->ref.initializeOwned(); t->sharable = true; t->alloc = alloc; if (!alloc) { diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index f605a82dfe..6bac127a82 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -63,7 +63,7 @@ QMapData *QMapData::createData(int alignment) Node *e = reinterpret_cast<Node *>(d); e->backward = e; e->forward[0] = e; - d->ref = 1; + d->ref.initializeOwned(); d->topLevel = 0; d->size = 0; d->randomBits = 0; diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h index 619f61e072..6d030cc0b3 100644 --- a/src/corelib/tools/qrefcount.h +++ b/src/corelib/tools/qrefcount.h @@ -75,10 +75,8 @@ public: { return !atomic.load(); } inline operator int() const { return atomic.load(); } - inline RefCount &operator=(int value) - { atomic.store(value); return *this; } - inline RefCount &operator=(const RefCount &other) - { atomic.store(other.atomic.load()); return *this; } + + void initializeOwned() { atomic.store(1); } QBasicAtomicInt atomic; }; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index fb818e37b8..02d6788701 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1032,7 +1032,7 @@ QString::QString(const QChar *unicode, int size) } else { d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = (uint) size; d->capacityReserved = false; @@ -1064,7 +1064,7 @@ QString::QString(const QChar *unicode) } else { d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = (uint) size; d->capacityReserved = false; @@ -1089,7 +1089,7 @@ QString::QString(int size, QChar ch) } else { d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = (uint) size; d->capacityReserved = false; @@ -1113,7 +1113,7 @@ QString::QString(int size, Qt::Initialization) { d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = (uint) size; d->capacityReserved = false; @@ -1135,7 +1135,7 @@ QString::QString(QChar ch) { d = (Data *) qMalloc(sizeof(Data) + 2*sizeof(QChar)); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = 1; d->alloc = 1; d->capacityReserved = false; @@ -1314,7 +1314,7 @@ void QString::realloc(int alloc) if (d->ref != 1 || d->offset) { Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + (alloc+1) * sizeof(QChar))); Q_CHECK_PTR(x); - x->ref = 1; + x->ref.initializeOwned(); x->size = qMin(alloc, d->size); x->alloc = (uint) alloc; x->capacityReserved = d->capacityReserved; @@ -3758,7 +3758,7 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) size = qstrlen(str); d = static_cast<Data *>(qMalloc(sizeof(Data) + (size+1) * sizeof(QChar))); Q_CHECK_PTR(d); - d->ref = 1; + d->ref.initializeOwned(); d->size = size; d->alloc = (uint) size; d->capacityReserved = false; @@ -7074,7 +7074,7 @@ QString QString::fromRawData(const QChar *unicode, int size) } else { x = static_cast<Data *>(qMalloc(sizeof(Data) + sizeof(ushort))); Q_CHECK_PTR(x); - x->ref = 1; + x->ref.initializeOwned(); x->size = size; x->alloc = 0; x->capacityReserved = false; diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index eab9311eb3..f408f6571f 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -411,7 +411,7 @@ template <typename T> QVector<T>::QVector(int asize) { d = malloc(asize); - d->ref = 1; + d->ref.initializeOwned(); d->alloc = d->size = asize; d->sharable = true; d->capacity = false; @@ -429,7 +429,7 @@ template <typename T> QVector<T>::QVector(int asize, const T &t) { d = malloc(asize); - d->ref = 1; + d->ref.initializeOwned(); d->alloc = d->size = asize; d->sharable = true; d->capacity = false; @@ -443,7 +443,7 @@ template <typename T> QVector<T>::QVector(std::initializer_list<T> args) { d = malloc(int(args.size())); - d->ref = 1; + d->ref.initializeOwned(); d->alloc = d->size = int(args.size()); d->sharable = true; d->capacity = false; @@ -515,7 +515,7 @@ void QVector<T>::realloc(int asize, int aalloc) QT_RETHROW; } } - x.d->ref = 1; + x.d->ref.initializeOwned(); x.d->alloc = aalloc; x.d->sharable = true; x.d->capacity = d->capacity; |