Rename AllocationPosition enum and its members
Use GrowsAt* and GrowthPosition as that is clearer. Change-Id: I3c173797dec3620f508156efc0c51b4d2cd3e142 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
edd1e931d1
commit
1282c05cdc
@ -1730,7 +1730,7 @@ void QByteArray::reallocGrowData(qsizetype n)
|
|||||||
n = 1;
|
n = 1;
|
||||||
|
|
||||||
if (d->needsDetach()) {
|
if (d->needsDetach()) {
|
||||||
DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::AllocateAtEnd));
|
DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::GrowsAtEnd));
|
||||||
dd->copyAppend(d.data(), d.data() + d.size);
|
dd->copyAppend(d.data(), d.data() + d.size);
|
||||||
dd.data()[dd.size] = 0;
|
dd.data()[dd.size] = 0;
|
||||||
d = dd;
|
d = dd;
|
||||||
@ -1934,7 +1934,7 @@ QByteArray &QByteArray::insert(qsizetype i, QByteArrayView data)
|
|||||||
// the old memory:
|
// the old memory:
|
||||||
DataPointer detached{}; // construction is free
|
DataPointer detached{}; // construction is free
|
||||||
if (d->needsDetach() || i + size - d->size > d.freeSpaceAtEnd()) {
|
if (d->needsDetach() || i + size - d->size > d.freeSpaceAtEnd()) {
|
||||||
detached = DataPointer::allocateGrow(d, i + size - d->size, Data::AllocateAtEnd);
|
detached = DataPointer::allocateGrow(d, i + size - d->size, Data::GrowsAtEnd);
|
||||||
detached->copyAppend(d.constBegin(), d.constEnd());
|
detached->copyAppend(d.constBegin(), d.constEnd());
|
||||||
d.swap(detached);
|
d.swap(detached);
|
||||||
}
|
}
|
||||||
@ -1993,7 +1993,7 @@ QByteArray &QByteArray::insert(qsizetype i, qsizetype count, char ch)
|
|||||||
if (i >= d->size) {
|
if (i >= d->size) {
|
||||||
// handle this specially, as QArrayDataOps::insert() doesn't handle out of bounds positions
|
// handle this specially, as QArrayDataOps::insert() doesn't handle out of bounds positions
|
||||||
if (d->needsDetach() || i + count - d->size > d.freeSpaceAtEnd()) {
|
if (d->needsDetach() || i + count - d->size > d.freeSpaceAtEnd()) {
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, i + count - d->size, Data::AllocateAtEnd));
|
DataPointer detached(DataPointer::allocateGrow(d, i + count - d->size, Data::GrowsAtEnd));
|
||||||
detached->copyAppend(d.constBegin(), d.constEnd());
|
detached->copyAppend(d.constBegin(), d.constEnd());
|
||||||
d.swap(detached);
|
d.swap(detached);
|
||||||
}
|
}
|
||||||
|
@ -2526,7 +2526,7 @@ void QString::reallocGrowData(qsizetype n)
|
|||||||
n = 1;
|
n = 1;
|
||||||
|
|
||||||
if (d->needsDetach()) {
|
if (d->needsDetach()) {
|
||||||
DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::AllocateAtEnd));
|
DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::GrowsAtEnd));
|
||||||
dd->copyAppend(d.data(), d.data() + d.size);
|
dd->copyAppend(d.data(), d.data() + d.size);
|
||||||
dd.data()[dd.size] = 0;
|
dd.data()[dd.size] = 0;
|
||||||
d = dd;
|
d = dd;
|
||||||
@ -2737,7 +2737,7 @@ QString& QString::insert(qsizetype i, const QChar *unicode, qsizetype size)
|
|||||||
// the old memory:
|
// the old memory:
|
||||||
DataPointer detached{}; // construction is free
|
DataPointer detached{}; // construction is free
|
||||||
if (d->needsDetach() || i + size - d->size > d.freeSpaceAtEnd()) {
|
if (d->needsDetach() || i + size - d->size > d.freeSpaceAtEnd()) {
|
||||||
detached = DataPointer::allocateGrow(d, i + size - d->size, Data::AllocateAtEnd);
|
detached = DataPointer::allocateGrow(d, i + size - d->size, Data::GrowsAtEnd);
|
||||||
detached->copyAppend(d.constBegin(), d.constEnd());
|
detached->copyAppend(d.constBegin(), d.constEnd());
|
||||||
d.swap(detached);
|
d.swap(detached);
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,9 @@ struct Q_CORE_EXPORT QArrayData
|
|||||||
KeepSize
|
KeepSize
|
||||||
};
|
};
|
||||||
|
|
||||||
enum AllocationPosition {
|
enum GrowthPosition {
|
||||||
AllocateAtEnd,
|
GrowsAtEnd,
|
||||||
AllocateAtBeginning
|
GrowsAtBeginning
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ArrayOption {
|
enum ArrayOption {
|
||||||
|
@ -1185,9 +1185,9 @@ public:
|
|||||||
void insert(qsizetype i, qsizetype n, parameter_type t)
|
void insert(qsizetype i, qsizetype n, parameter_type t)
|
||||||
{
|
{
|
||||||
if (this->needsDetach() || (n > this->freeSpaceAtBegin() && n > this->freeSpaceAtEnd())) {
|
if (this->needsDetach() || (n > this->freeSpaceAtBegin() && n > this->freeSpaceAtEnd())) {
|
||||||
typename Data::AllocationPosition pos = Data::AllocateAtEnd;
|
typename Data::GrowthPosition pos = Data::GrowsAtEnd;
|
||||||
if (this->size != 0 && i <= (this->size >> 1))
|
if (this->size != 0 && i <= (this->size >> 1))
|
||||||
pos = Data::AllocateAtBeginning;
|
pos = Data::GrowsAtBeginning;
|
||||||
|
|
||||||
DataPointer detached(DataPointer::allocateGrow(*this, n, pos));
|
DataPointer detached(DataPointer::allocateGrow(*this, n, pos));
|
||||||
const_iterator where = this->constBegin() + i;
|
const_iterator where = this->constBegin() + i;
|
||||||
@ -1219,9 +1219,9 @@ public:
|
|||||||
void insert(qsizetype i, const T *data, qsizetype n)
|
void insert(qsizetype i, const T *data, qsizetype n)
|
||||||
{
|
{
|
||||||
if (this->needsDetach() || (n > this->freeSpaceAtBegin() && n > this->freeSpaceAtEnd())) {
|
if (this->needsDetach() || (n > this->freeSpaceAtBegin() && n > this->freeSpaceAtEnd())) {
|
||||||
typename Data::AllocationPosition pos = Data::AllocateAtEnd;
|
typename Data::GrowthPosition pos = Data::GrowsAtEnd;
|
||||||
if (this->size != 0 && i <= (this->size >> 1))
|
if (this->size != 0 && i <= (this->size >> 1))
|
||||||
pos = Data::AllocateAtBeginning;
|
pos = Data::GrowsAtBeginning;
|
||||||
|
|
||||||
DataPointer detached(DataPointer::allocateGrow(*this, n, pos));
|
DataPointer detached(DataPointer::allocateGrow(*this, n, pos));
|
||||||
auto where = this->constBegin() + i;
|
auto where = this->constBegin() + i;
|
||||||
|
@ -207,7 +207,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allocate and grow. Ensure that at the minimum requiredSpace is available at the requested end
|
// allocate and grow. Ensure that at the minimum requiredSpace is available at the requested end
|
||||||
static QArrayDataPointer allocateGrow(const QArrayDataPointer &from, qsizetype n, QArrayData::AllocationPosition position)
|
static QArrayDataPointer allocateGrow(const QArrayDataPointer &from, qsizetype n, QArrayData::GrowthPosition position)
|
||||||
{
|
{
|
||||||
// calculate new capacity. We keep the free capacity at the side that does not have to grow
|
// calculate new capacity. We keep the free capacity at the side that does not have to grow
|
||||||
// to avoid quadratic behavior with mixed append/prepend cases
|
// to avoid quadratic behavior with mixed append/prepend cases
|
||||||
@ -216,7 +216,7 @@ public:
|
|||||||
qsizetype minimalCapacity = qMax(from.size, from.constAllocatedCapacity()) + n;
|
qsizetype minimalCapacity = qMax(from.size, from.constAllocatedCapacity()) + n;
|
||||||
// subtract the free space at the side we want to allocate. This ensures that the total size requested is
|
// subtract the free space at the side we want to allocate. This ensures that the total size requested is
|
||||||
// the existing allocation at the other side + size + n.
|
// the existing allocation at the other side + size + n.
|
||||||
minimalCapacity -= (position == QArrayData::AllocateAtEnd) ? from.freeSpaceAtEnd() : from.freeSpaceAtBegin();
|
minimalCapacity -= (position == QArrayData::GrowsAtEnd) ? from.freeSpaceAtEnd() : from.freeSpaceAtBegin();
|
||||||
qsizetype capacity = from.detachCapacity(minimalCapacity);
|
qsizetype capacity = from.detachCapacity(minimalCapacity);
|
||||||
const bool grows = capacity > from.constAllocatedCapacity();
|
const bool grows = capacity > from.constAllocatedCapacity();
|
||||||
auto [header, dataPtr] = Data::allocate(capacity, grows ? QArrayData::Grow : QArrayData::KeepSize);
|
auto [header, dataPtr] = Data::allocate(capacity, grows ? QArrayData::Grow : QArrayData::KeepSize);
|
||||||
@ -228,7 +228,7 @@ public:
|
|||||||
// * when growing forward, adjust by the previous data pointer offset
|
// * when growing forward, adjust by the previous data pointer offset
|
||||||
|
|
||||||
// TODO: what's with CapacityReserved?
|
// TODO: what's with CapacityReserved?
|
||||||
dataPtr += (position == QArrayData::AllocateAtBeginning) ? qMax(0, (header->alloc - from.size - n) / 2)
|
dataPtr += (position == QArrayData::GrowsAtBeginning) ? qMax(0, (header->alloc - from.size - n) / 2)
|
||||||
: from.freeSpaceAtBegin();
|
: from.freeSpaceAtBegin();
|
||||||
header->flags = from.flags();
|
header->flags = from.flags();
|
||||||
return QArrayDataPointer(header, dataPtr);
|
return QArrayDataPointer(header, dataPtr);
|
||||||
@ -249,12 +249,12 @@ public:
|
|||||||
Q_ASSERT(n > 0);
|
Q_ASSERT(n > 0);
|
||||||
|
|
||||||
if constexpr (!QTypeInfo<T>::isRelocatable || alignof(T) > alignof(std::max_align_t)) {
|
if constexpr (!QTypeInfo<T>::isRelocatable || alignof(T) > alignof(std::max_align_t)) {
|
||||||
QArrayDataPointer dd(allocateGrow(from, n, QArrayData::AllocateAtEnd));
|
QArrayDataPointer dd(allocateGrow(from, n, QArrayData::GrowsAtEnd));
|
||||||
dd->copyAppend(from.data(), from.data() + from.size);
|
dd->copyAppend(from.data(), from.data() + from.size);
|
||||||
from.swap(dd);
|
from.swap(dd);
|
||||||
} else {
|
} else {
|
||||||
if (from.needsDetach()) {
|
if (from.needsDetach()) {
|
||||||
QArrayDataPointer dd(allocateGrow(from, n, QArrayData::AllocateAtEnd));
|
QArrayDataPointer dd(allocateGrow(from, n, QArrayData::GrowsAtEnd));
|
||||||
dd->copyAppend(from.data(), from.data() + from.size);
|
dd->copyAppend(from.data(), from.data() + from.size);
|
||||||
from.swap(dd);
|
from.swap(dd);
|
||||||
} else {
|
} else {
|
||||||
|
@ -670,7 +670,7 @@ inline void QList<T>::append(const_iterator i1, const_iterator i2)
|
|||||||
return;
|
return;
|
||||||
const auto distance = std::distance(i1, i2);
|
const auto distance = std::distance(i1, i2);
|
||||||
if (d->needsDetach() || distance > d.freeSpaceAtEnd()) {
|
if (d->needsDetach() || distance > d.freeSpaceAtEnd()) {
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, distance, QArrayData::AllocateAtEnd));
|
DataPointer detached(DataPointer::allocateGrow(d, distance, QArrayData::GrowsAtEnd));
|
||||||
detached->copyAppend(constBegin(), constEnd());
|
detached->copyAppend(constBegin(), constEnd());
|
||||||
detached->copyAppend(i1, i2);
|
detached->copyAppend(i1, i2);
|
||||||
d.swap(detached);
|
d.swap(detached);
|
||||||
@ -689,7 +689,7 @@ inline void QList<T>::append(QList<T> &&other)
|
|||||||
return append(other);
|
return append(other);
|
||||||
|
|
||||||
if (d->needsDetach() || other.size() > d.freeSpaceAtEnd()) {
|
if (d->needsDetach() || other.size() > d.freeSpaceAtEnd()) {
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, other.size(), QArrayData::AllocateAtEnd));
|
DataPointer detached(DataPointer::allocateGrow(d, other.size(), QArrayData::GrowsAtEnd));
|
||||||
|
|
||||||
if (!d->needsDetach())
|
if (!d->needsDetach())
|
||||||
detached->moveAppend(begin(), end());
|
detached->moveAppend(begin(), end());
|
||||||
@ -709,7 +709,7 @@ template<typename... Args>
|
|||||||
inline typename QList<T>::reference QList<T>::emplaceFront(Args &&... args)
|
inline typename QList<T>::reference QList<T>::emplaceFront(Args &&... args)
|
||||||
{
|
{
|
||||||
if (d->needsDetach() || !d.freeSpaceAtBegin()) {
|
if (d->needsDetach() || !d.freeSpaceAtBegin()) {
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, 1, QArrayData::AllocateAtBeginning));
|
DataPointer detached(DataPointer::allocateGrow(d, 1, QArrayData::GrowsAtBeginning));
|
||||||
|
|
||||||
detached->emplaceBack(std::forward<Args>(args)...);
|
detached->emplaceBack(std::forward<Args>(args)...);
|
||||||
if (!d.needsDetach())
|
if (!d.needsDetach())
|
||||||
@ -742,9 +742,9 @@ QList<T>::emplace(qsizetype i, Args&&... args)
|
|||||||
Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range");
|
Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range");
|
||||||
|
|
||||||
if (d->needsDetach() || (d.size == d.constAllocatedCapacity())) {
|
if (d->needsDetach() || (d.size == d.constAllocatedCapacity())) {
|
||||||
typename QArrayData::AllocationPosition pos = QArrayData::AllocateAtEnd;
|
typename QArrayData::GrowthPosition pos = QArrayData::GrowsAtEnd;
|
||||||
if (d.size != 0 && i <= (d.size >> 1))
|
if (d.size != 0 && i <= (d.size >> 1))
|
||||||
pos = QArrayData::AllocateAtBeginning;
|
pos = QArrayData::GrowsAtBeginning;
|
||||||
|
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, 1, pos));
|
DataPointer detached(DataPointer::allocateGrow(d, 1, pos));
|
||||||
const_iterator where = constBegin() + i;
|
const_iterator where = constBegin() + i;
|
||||||
@ -772,7 +772,7 @@ inline typename QList<T>::reference QList<T>::emplaceBack(Args &&... args)
|
|||||||
// condition below should follow the condition in QArrayDataPointer::reallocateGrow()
|
// condition below should follow the condition in QArrayDataPointer::reallocateGrow()
|
||||||
if constexpr (!QTypeInfo<T>::isRelocatable || alignof(T) > alignof(std::max_align_t)) {
|
if constexpr (!QTypeInfo<T>::isRelocatable || alignof(T) > alignof(std::max_align_t)) {
|
||||||
// avoid taking a temporary copy of Args
|
// avoid taking a temporary copy of Args
|
||||||
DataPointer detached(DataPointer::allocateGrow(d, 1, QArrayData::AllocateAtEnd));
|
DataPointer detached(DataPointer::allocateGrow(d, 1, QArrayData::GrowsAtEnd));
|
||||||
detached->copyAppend(constBegin(), constEnd());
|
detached->copyAppend(constBegin(), constEnd());
|
||||||
detached->emplace(detached.end(), std::forward<Args>(args)...);
|
detached->emplace(detached.end(), std::forward<Args>(args)...);
|
||||||
d.swap(detached);
|
d.swap(detached);
|
||||||
|
@ -216,7 +216,7 @@ public:
|
|||||||
|
|
||||||
auto requiredSize = qsizetype(last - first);
|
auto requiredSize = qsizetype(last - first);
|
||||||
if (d->needsDetach() || d.freeSpaceAtEnd() < requiredSize) {
|
if (d->needsDetach() || d.freeSpaceAtEnd() < requiredSize) {
|
||||||
SimpleVector detached(DataPointer::allocateGrow(d, requiredSize, QArrayData::AllocateAtEnd));
|
SimpleVector detached(DataPointer::allocateGrow(d, requiredSize, QArrayData::GrowsAtEnd));
|
||||||
|
|
||||||
if (d->size) {
|
if (d->size) {
|
||||||
const T *const begin = constBegin();
|
const T *const begin = constBegin();
|
||||||
|
@ -1100,7 +1100,7 @@ void tst_QArrayData::arrayOpsExtra_data()
|
|||||||
void tst_QArrayData::arrayOpsExtra()
|
void tst_QArrayData::arrayOpsExtra()
|
||||||
{
|
{
|
||||||
QSKIP("Skipped while changing QArrayData operations.", SkipAll);
|
QSKIP("Skipped while changing QArrayData operations.", SkipAll);
|
||||||
QFETCH(QArrayData::AllocationPosition, allocationPosition);
|
QFETCH(QArrayData::GrowthPosition, GrowthPosition);
|
||||||
CountedObject::LeakChecker leakChecker; Q_UNUSED(leakChecker);
|
CountedObject::LeakChecker leakChecker; Q_UNUSED(leakChecker);
|
||||||
|
|
||||||
constexpr size_t inputSize = 5;
|
constexpr size_t inputSize = 5;
|
||||||
@ -1119,11 +1119,11 @@ void tst_QArrayData::arrayOpsExtra()
|
|||||||
for (size_t i = 0; i < 5; ++i)
|
for (size_t i = 0; i < 5; ++i)
|
||||||
QCOMPARE(objArray[i].id, i);
|
QCOMPARE(objArray[i].id, i);
|
||||||
|
|
||||||
const auto setupDataPointers = [&allocationPosition] (size_t capacity, size_t initialSize = 0) {
|
const auto setupDataPointers = [&GrowthPosition] (size_t capacity, size_t initialSize = 0) {
|
||||||
const qsizetype alloc = qsizetype(capacity);
|
const qsizetype alloc = qsizetype(capacity);
|
||||||
auto i = QArrayDataPointer<int>::allocateGrow(QArrayDataPointer<int>(), alloc, allocationPosition);
|
auto i = QArrayDataPointer<int>::allocateGrow(QArrayDataPointer<int>(), alloc, GrowthPosition);
|
||||||
auto s = QArrayDataPointer<QString>::allocateGrow(QArrayDataPointer<QString>(), alloc, allocationPosition);
|
auto s = QArrayDataPointer<QString>::allocateGrow(QArrayDataPointer<QString>(), alloc, GrowthPosition);
|
||||||
auto o = QArrayDataPointer<CountedObject>::allocateGrow(QArrayDataPointer<CountedObject>(), alloc, allocationPosition);
|
auto o = QArrayDataPointer<CountedObject>::allocateGrow(QArrayDataPointer<CountedObject>(), alloc, GrowthPosition);
|
||||||
if (initialSize) {
|
if (initialSize) {
|
||||||
i->appendInitialize(initialSize);
|
i->appendInitialize(initialSize);
|
||||||
s->appendInitialize(initialSize);
|
s->appendInitialize(initialSize);
|
||||||
@ -1245,7 +1245,7 @@ void tst_QArrayData::arrayOpsExtra()
|
|||||||
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
||||||
|
|
||||||
// sanity checks:
|
// sanity checks:
|
||||||
if (allocationPosition & QArrayData::AllocateAtBeginning) {
|
if (GrowthPosition & QArrayData::GrowsAtBeginning) {
|
||||||
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
||||||
@ -1344,7 +1344,7 @@ void tst_QArrayData::arrayOpsExtra()
|
|||||||
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
||||||
|
|
||||||
// sanity checks:
|
// sanity checks:
|
||||||
if (allocationPosition & QArrayData::AllocateAtBeginning) {
|
if (GrowthPosition & QArrayData::GrowsAtBeginning) {
|
||||||
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
||||||
@ -1443,7 +1443,7 @@ void tst_QArrayData::arrayOpsExtra()
|
|||||||
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
std::generate(objData.begin(), objData.end(), [] () { return CountedObject(); });
|
||||||
|
|
||||||
// sanity checks:
|
// sanity checks:
|
||||||
if (allocationPosition & QArrayData::AllocateAtBeginning) {
|
if (GrowthPosition & QArrayData::GrowsAtBeginning) {
|
||||||
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
QVERIFY(intData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
QVERIFY(strData.freeSpaceAtBegin() > 0);
|
||||||
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
QVERIFY(objData.freeSpaceAtBegin() > 0);
|
||||||
@ -2034,7 +2034,7 @@ void tst_QArrayData::freeSpace()
|
|||||||
using DataPointer = QArrayDataPointer<Type>;
|
using DataPointer = QArrayDataPointer<Type>;
|
||||||
Q_UNUSED(dummy);
|
Q_UNUSED(dummy);
|
||||||
const qsizetype capacity = n + 1;
|
const qsizetype capacity = n + 1;
|
||||||
auto ptr = DataPointer::allocateGrow(DataPointer(), capacity, QArrayData::AllocateAtEnd);
|
auto ptr = DataPointer::allocateGrow(DataPointer(), capacity, QArrayData::GrowsAtEnd);
|
||||||
const auto alloc = qsizetype(ptr.constAllocatedCapacity());
|
const auto alloc = qsizetype(ptr.constAllocatedCapacity());
|
||||||
QVERIFY(alloc >= capacity);
|
QVERIFY(alloc >= capacity);
|
||||||
QCOMPARE(ptr.freeSpaceAtBegin() + ptr.freeSpaceAtEnd(), alloc);
|
QCOMPARE(ptr.freeSpaceAtBegin() + ptr.freeSpaceAtEnd(), alloc);
|
||||||
@ -2048,15 +2048,15 @@ void tst_QArrayData::freeSpace()
|
|||||||
|
|
||||||
void tst_QArrayData::dataPointerAllocate_data()
|
void tst_QArrayData::dataPointerAllocate_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QArrayData::AllocationPosition>("allocationPosition");
|
QTest::addColumn<QArrayData::GrowthPosition>("GrowthPosition");
|
||||||
|
|
||||||
QTest::newRow("at-end") << QArrayData::AllocateAtEnd;
|
QTest::newRow("at-end") << QArrayData::GrowsAtEnd;
|
||||||
QTest::newRow("at-begin") << QArrayData::AllocateAtBeginning;
|
QTest::newRow("at-begin") << QArrayData::GrowsAtBeginning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QArrayData::dataPointerAllocate()
|
void tst_QArrayData::dataPointerAllocate()
|
||||||
{
|
{
|
||||||
QFETCH(QArrayData::AllocationPosition, allocationPosition);
|
QFETCH(QArrayData::GrowthPosition, GrowthPosition);
|
||||||
const auto createDataPointer = [] (qsizetype capacity, auto initValue) {
|
const auto createDataPointer = [] (qsizetype capacity, auto initValue) {
|
||||||
using Type = std::decay_t<decltype(initValue)>;
|
using Type = std::decay_t<decltype(initValue)>;
|
||||||
Q_UNUSED(initValue);
|
Q_UNUSED(initValue);
|
||||||
@ -2072,16 +2072,16 @@ void tst_QArrayData::dataPointerAllocate()
|
|||||||
oldDataPointer->insert(0, 1, initValue); // trigger prepend
|
oldDataPointer->insert(0, 1, initValue); // trigger prepend
|
||||||
QVERIFY(!oldDataPointer.needsDetach());
|
QVERIFY(!oldDataPointer.needsDetach());
|
||||||
|
|
||||||
auto newDataPointer = DataPointer::allocateGrow(oldDataPointer, newSize, allocationPosition);
|
auto newDataPointer = DataPointer::allocateGrow(oldDataPointer, newSize, GrowthPosition);
|
||||||
const auto newAlloc = newDataPointer.constAllocatedCapacity();
|
const auto newAlloc = newDataPointer.constAllocatedCapacity();
|
||||||
const auto freeAtBegin = newDataPointer.freeSpaceAtBegin();
|
const auto freeAtBegin = newDataPointer.freeSpaceAtBegin();
|
||||||
const auto freeAtEnd = newDataPointer.freeSpaceAtEnd();
|
const auto freeAtEnd = newDataPointer.freeSpaceAtEnd();
|
||||||
|
|
||||||
QVERIFY(newAlloc > oldDataPointer.constAllocatedCapacity());
|
QVERIFY(newAlloc > oldDataPointer.constAllocatedCapacity());
|
||||||
QCOMPARE(freeAtBegin + freeAtEnd, newAlloc);
|
QCOMPARE(freeAtBegin + freeAtEnd, newAlloc);
|
||||||
if (allocationPosition == QArrayData::AllocateAtBeginning) {
|
if (GrowthPosition == QArrayData::GrowsAtBeginning) {
|
||||||
QVERIFY(freeAtBegin > 0);
|
QVERIFY(freeAtBegin > 0);
|
||||||
} else if (allocationPosition & QArrayData::AllocateAtEnd) {
|
} else if (GrowthPosition & QArrayData::GrowsAtEnd) {
|
||||||
QCOMPARE(freeAtBegin, oldDataPointer.freeSpaceAtBegin());
|
QCOMPARE(freeAtBegin, oldDataPointer.freeSpaceAtBegin());
|
||||||
QVERIFY(freeAtEnd > 0);
|
QVERIFY(freeAtEnd > 0);
|
||||||
}
|
}
|
||||||
@ -2104,16 +2104,16 @@ void tst_QArrayData::dataPointerAllocate()
|
|||||||
auto oldDataPointerCopy = oldDataPointer; // force detach later
|
auto oldDataPointerCopy = oldDataPointer; // force detach later
|
||||||
QVERIFY(oldDataPointer.needsDetach());
|
QVERIFY(oldDataPointer.needsDetach());
|
||||||
|
|
||||||
auto newDataPointer = DataPointer::allocateGrow(oldDataPointer, oldDataPointer->detachCapacity(newSize), allocationPosition);
|
auto newDataPointer = DataPointer::allocateGrow(oldDataPointer, oldDataPointer->detachCapacity(newSize), GrowthPosition);
|
||||||
const auto newAlloc = newDataPointer.constAllocatedCapacity();
|
const auto newAlloc = newDataPointer.constAllocatedCapacity();
|
||||||
const auto freeAtBegin = newDataPointer.freeSpaceAtBegin();
|
const auto freeAtBegin = newDataPointer.freeSpaceAtBegin();
|
||||||
const auto freeAtEnd = newDataPointer.freeSpaceAtEnd();
|
const auto freeAtEnd = newDataPointer.freeSpaceAtEnd();
|
||||||
|
|
||||||
QVERIFY(newAlloc > oldDataPointer.constAllocatedCapacity());
|
QVERIFY(newAlloc > oldDataPointer.constAllocatedCapacity());
|
||||||
QCOMPARE(freeAtBegin + freeAtEnd, newAlloc);
|
QCOMPARE(freeAtBegin + freeAtEnd, newAlloc);
|
||||||
if (allocationPosition == QArrayData::AllocateAtBeginning) {
|
if (GrowthPosition == QArrayData::GrowsAtBeginning) {
|
||||||
QVERIFY(freeAtBegin > 0);
|
QVERIFY(freeAtBegin > 0);
|
||||||
} else if (allocationPosition & QArrayData::AllocateAtEnd) {
|
} else if (GrowthPosition & QArrayData::GrowsAtEnd) {
|
||||||
QCOMPARE(freeAtBegin, oldDataPointer.freeSpaceAtBegin());
|
QCOMPARE(freeAtBegin, oldDataPointer.freeSpaceAtBegin());
|
||||||
QVERIFY(freeAtEnd > 0);
|
QVERIFY(freeAtEnd > 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user