From 8fb45ae5b8b8ad276aeb9bc9e40f351f47523087 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 4 Jun 2012 22:04:13 +0200 Subject: Introduce QArrayData::allocatedCapacity() and use it instead of d->alloc In almost all cases, use d->allocatedCapacity() or d->constAllocatedCapacity() instead of d->alloc, since they do the same thing (right now). In the future, the functions will be changed. There is a separate const version because most const code should not need to know the allocation size -- only mutating code should need to know that There are a few cases where d->alloc was replaced with a better alternative, like d->size. The one case that remains in the code will be replaced by a different test when it's available. Change-Id: I48135469db4caf150f82df93fff42d2309b23719 Reviewed-by: Simon Hausmann --- tests/auto/corelib/tools/qarraydata/simplevector.h | 2 +- .../auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h index b5308e2231..f3e3a1bb50 100644 --- a/tests/auto/corelib/tools/qarraydata/simplevector.h +++ b/tests/auto/corelib/tools/qarraydata/simplevector.h @@ -90,7 +90,7 @@ public: bool isSharedWith(const SimpleVector &other) const { return d == other.d; } size_t size() const { return d->size; } - size_t capacity() const { return d->alloc; } + size_t capacity() const { return d->allocatedCapacity(); } iterator begin() { detach(); return d->begin(); } iterator end() { detach(); return d->end(); } diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 1a043f7797..23ea417481 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -154,10 +154,10 @@ void tst_QArrayData::sharedNullEmpty() QVERIFY(null != empty); QCOMPARE(null->size, 0); - QCOMPARE(null->alloc, 0u); + QCOMPARE(null->allocatedCapacity(), size_t(0)); QCOMPARE(empty->size, 0); - QCOMPARE(empty->alloc, 0u); + QCOMPARE(empty->allocatedCapacity(), size_t(0)); } void tst_QArrayData::staticData() @@ -597,9 +597,9 @@ void tst_QArrayData::allocate() QCOMPARE(data->size, 0); if (allocateOptions & QArrayData::GrowsForward) - QVERIFY(data->alloc > uint(capacity)); + QVERIFY(data->allocatedCapacity() > uint(capacity)); else - QCOMPARE(data->alloc, uint(capacity)); + QCOMPARE(data->allocatedCapacity(), size_t(capacity)); QCOMPARE(bool(data->flags & QArrayData::CapacityReserved), isCapacityReserved); // Check that the allocated array can be used. Best tested with a @@ -642,9 +642,9 @@ void tst_QArrayData::reallocate() QCOMPARE(data->size, capacity); if (allocateOptions & QArrayData::GrowsForward) - QVERIFY(data->alloc > uint(newCapacity)); + QVERIFY(data->allocatedCapacity() > size_t(newCapacity)); else - QCOMPARE(data->alloc, uint(newCapacity)); + QCOMPARE(data->allocatedCapacity(), size_t(newCapacity)); QCOMPARE(!(data->flags & QArrayData::CapacityReserved), !isCapacityReserved); for (int i = 0; i < capacity; ++i) @@ -684,7 +684,7 @@ void tst_QArrayData::alignment() QVERIFY(data); QCOMPARE(data->size, 0); - QVERIFY(data->alloc >= uint(8)); + QVERIFY(data->allocatedCapacity() >= uint(8)); // These conditions should hold as long as header and array are // allocated together @@ -756,7 +756,7 @@ void tst_QArrayData::typedData() QVERIFY(array); QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. @@ -776,7 +776,7 @@ void tst_QArrayData::typedData() QVERIFY(array); QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. @@ -796,7 +796,7 @@ void tst_QArrayData::typedData() QVERIFY(array); QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. -- cgit v1.2.3