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>
This commit is contained in:
João Abecasis 2011-12-16 17:22:45 +01:00 committed by Qt by Nokia
parent 7d16ea4033
commit 7fadc3ce32
10 changed files with 29 additions and 31 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;
};

View File

@ -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;

View File

@ -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;

View File

@ -289,7 +289,7 @@ public:
QVector<T> mutateToVector()
{
Data *d = toBase(m_begin);
d->ref = 1;
d->ref.initializeOwned();
d->alloc = m_alloc;
d->size = m_size;
d->sharable = 0;