, 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>
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;
d.take(); // realloc was successful
d.reset(p);
}
- d->ref = 1;
+ d->ref.initializeOwned();
d->size = len;
d->alloc = len;
d->capacityReserved = false;
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;
} 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;
} 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;
{
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;
//
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;
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;
} 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;
d = new QHashData;
d->fakeNext = 0;
d->buckets = 0;
- d->ref = 1;
+ d->ref.initializeOwned();
d->size = size;
d->nodeSize = nodeSize;
d->userNumBits = userNumBits;
{
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;
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:
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) {
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;
{ 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;
};
} 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;
} 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;
} 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;
{
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;
{
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;
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;
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;
} 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;
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;
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;
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;
QT_RETHROW;
}
}
- x.d->ref = 1;
+ x.d->ref.initializeOwned();
x.d->alloc = aalloc;
x.d->sharable = true;
x.d->capacity = d->capacity;
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;