summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlist.cpp')
-rw-r--r--src/corelib/tools/qlist.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 9b40e2d37a..c87b3e7d24 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
the number of elements in the list.
*/
-const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, true, { 0 } };
+const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } };
static int grow(int size)
{
@@ -87,8 +87,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num)
Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *)));
Q_CHECK_PTR(t);
- t->ref = 1;
- t->sharable = true;
+ t->ref.initializeOwned();
t->alloc = alloc;
// The space reservation algorithm's optimization is biased towards appending:
// Something which looks like an append will put the data at the beginning,
@@ -129,8 +128,7 @@ QListData::Data *QListData::detach(int alloc)
Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *)));
Q_CHECK_PTR(t);
- t->ref = 1;
- t->sharable = true;
+ t->ref.initializeOwned();
t->alloc = alloc;
if (!alloc) {
t->begin = 0;
@@ -146,7 +144,7 @@ QListData::Data *QListData::detach(int alloc)
void QListData::realloc(int alloc)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *)));
Q_CHECK_PTR(x);
@@ -159,7 +157,7 @@ void QListData::realloc(int alloc)
// ensures that enough space is available to append n elements
void **QListData::append(int n)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
int e = d->end;
if (e + n > d->alloc) {
int b = d->begin;
@@ -190,7 +188,7 @@ void **QListData::append(const QListData& l)
void **QListData::prepend()
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
if (d->begin == 0) {
if (d->end >= d->alloc / 3)
realloc(grow(d->alloc + 1));
@@ -208,7 +206,7 @@ void **QListData::prepend()
void **QListData::insert(int i)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
if (i <= 0)
return prepend();
int size = d->end - d->begin;
@@ -247,7 +245,7 @@ void **QListData::insert(int i)
void QListData::remove(int i)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
i += d->begin;
if (i - d->begin < d->end - i) {
if (int offset = i - d->begin)
@@ -262,7 +260,7 @@ void QListData::remove(int i)
void QListData::remove(int i, int n)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
i += d->begin;
int middle = i + n/2;
if (middle - d->begin < d->end - middle) {
@@ -278,7 +276,7 @@ void QListData::remove(int i, int n)
void QListData::move(int from, int to)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
if (from == to)
return;
@@ -318,7 +316,7 @@ void QListData::move(int from, int to)
void **QListData::erase(void **xi)
{
- Q_ASSERT(d->ref == 1);
+ Q_ASSERT(!d->ref.isShared());
int i = xi - (d->array + d->begin);
remove(i);
return d->array + d->begin + i;