Rename QArrayData::AllocateOption to AllocationOption
Change-Id: Id3e7c748b4b40d703ad1785c903c96bdd968390e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
parent
f4c1e2c40f
commit
b3a4d3e328
@ -49,7 +49,7 @@ static const QArrayData qt_array_empty = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0
|
|||||||
static const QArrayData qt_array_unsharable_empty = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
|
static const QArrayData qt_array_unsharable_empty = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
|
||||||
|
|
||||||
QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
|
QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
|
||||||
size_t capacity, AllocateOptions options)
|
size_t capacity, AllocationOptions options)
|
||||||
{
|
{
|
||||||
// Alignment is a power of two
|
// Alignment is a power of two
|
||||||
Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData)
|
Q_ASSERT(alignment >= Q_ALIGNOF(QArrayData)
|
||||||
|
@ -81,7 +81,7 @@ struct Q_CORE_EXPORT QArrayData
|
|||||||
return alloc != 0;
|
return alloc != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AllocateOption {
|
enum AllocationOption {
|
||||||
CapacityReserved = 0x1,
|
CapacityReserved = 0x1,
|
||||||
Unsharable = 0x2,
|
Unsharable = 0x2,
|
||||||
RawData = 0x4,
|
RawData = 0x4,
|
||||||
@ -89,11 +89,11 @@ struct Q_CORE_EXPORT QArrayData
|
|||||||
Default = 0
|
Default = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(AllocateOptions, AllocateOption)
|
Q_DECLARE_FLAGS(AllocationOptions, AllocationOption)
|
||||||
|
|
||||||
AllocateOptions detachFlags() const
|
AllocationOptions detachFlags() const
|
||||||
{
|
{
|
||||||
AllocateOptions result;
|
AllocationOptions result;
|
||||||
if (!ref.isSharable())
|
if (!ref.isSharable())
|
||||||
result |= Unsharable;
|
result |= Unsharable;
|
||||||
if (capacityReserved)
|
if (capacityReserved)
|
||||||
@ -101,23 +101,24 @@ struct Q_CORE_EXPORT QArrayData
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AllocateOptions cloneFlags() const
|
AllocationOptions cloneFlags() const
|
||||||
{
|
{
|
||||||
AllocateOptions result;
|
AllocationOptions result;
|
||||||
if (capacityReserved)
|
if (capacityReserved)
|
||||||
result |= CapacityReserved;
|
result |= CapacityReserved;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QArrayData *allocate(size_t objectSize, size_t alignment,
|
static QArrayData *allocate(size_t objectSize, size_t alignment,
|
||||||
size_t capacity, AllocateOptions options = Default) Q_REQUIRED_RESULT;
|
size_t capacity, AllocationOptions options = Default)
|
||||||
|
Q_REQUIRED_RESULT;
|
||||||
static void deallocate(QArrayData *data, size_t objectSize,
|
static void deallocate(QArrayData *data, size_t objectSize,
|
||||||
size_t alignment);
|
size_t alignment);
|
||||||
|
|
||||||
static const QArrayData shared_null;
|
static const QArrayData shared_null;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocateOptions)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocationOptions)
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct QTypedArrayData
|
struct QTypedArrayData
|
||||||
@ -137,7 +138,7 @@ struct QTypedArrayData
|
|||||||
class AlignmentDummy { QArrayData header; T data; };
|
class AlignmentDummy { QArrayData header; T data; };
|
||||||
|
|
||||||
static QTypedArrayData *allocate(size_t capacity,
|
static QTypedArrayData *allocate(size_t capacity,
|
||||||
AllocateOptions options = Default) Q_REQUIRED_RESULT
|
AllocationOptions options = Default) Q_REQUIRED_RESULT
|
||||||
{
|
{
|
||||||
return static_cast<QTypedArrayData *>(QArrayData::allocate(sizeof(T),
|
return static_cast<QTypedArrayData *>(QArrayData::allocate(sizeof(T),
|
||||||
Q_ALIGNOF(AlignmentDummy), capacity, options));
|
Q_ALIGNOF(AlignmentDummy), capacity, options));
|
||||||
@ -149,7 +150,7 @@ struct QTypedArrayData
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QTypedArrayData *fromRawData(const T *data, size_t n,
|
static QTypedArrayData *fromRawData(const T *data, size_t n,
|
||||||
AllocateOptions options = Default)
|
AllocationOptions options = Default)
|
||||||
{
|
{
|
||||||
QTypedArrayData *result = allocate(0, options | RawData);
|
QTypedArrayData *result = allocate(0, options | RawData);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -151,7 +151,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Data *clone(QArrayData::AllocateOptions options) const Q_REQUIRED_RESULT
|
Data *clone(QArrayData::AllocationOptions options) const Q_REQUIRED_RESULT
|
||||||
{
|
{
|
||||||
QArrayDataPointer copy(Data::allocate(d->alloc ? d->alloc : d->size,
|
QArrayDataPointer copy(Data::allocate(d->alloc ? d->alloc : d->size,
|
||||||
options));
|
options));
|
||||||
|
@ -275,7 +275,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static SimpleVector fromRawData(const T *data, size_t size,
|
static SimpleVector fromRawData(const T *data, size_t size,
|
||||||
QArrayData::AllocateOptions options = Data::Default)
|
QArrayData::AllocationOptions options = Data::Default)
|
||||||
{
|
{
|
||||||
return SimpleVector(Data::fromRawData(data, size, options));
|
return SimpleVector(Data::fromRawData(data, size, options));
|
||||||
}
|
}
|
||||||
|
@ -546,13 +546,13 @@ struct Deallocator
|
|||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(const QArrayData *)
|
Q_DECLARE_METATYPE(const QArrayData *)
|
||||||
Q_DECLARE_METATYPE(QArrayData::AllocateOptions)
|
Q_DECLARE_METATYPE(QArrayData::AllocationOptions)
|
||||||
|
|
||||||
void tst_QArrayData::allocate_data()
|
void tst_QArrayData::allocate_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<size_t>("objectSize");
|
QTest::addColumn<size_t>("objectSize");
|
||||||
QTest::addColumn<size_t>("alignment");
|
QTest::addColumn<size_t>("alignment");
|
||||||
QTest::addColumn<QArrayData::AllocateOptions>("allocateOptions");
|
QTest::addColumn<QArrayData::AllocationOptions>("allocateOptions");
|
||||||
QTest::addColumn<bool>("isCapacityReserved");
|
QTest::addColumn<bool>("isCapacityReserved");
|
||||||
QTest::addColumn<bool>("isSharable");
|
QTest::addColumn<bool>("isSharable");
|
||||||
QTest::addColumn<const QArrayData *>("commonEmpty");
|
QTest::addColumn<const QArrayData *>("commonEmpty");
|
||||||
@ -575,7 +575,7 @@ void tst_QArrayData::allocate_data()
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
char const *description;
|
char const *description;
|
||||||
QArrayData::AllocateOptions allocateOptions;
|
QArrayData::AllocationOptions allocateOptions;
|
||||||
bool isCapacityReserved;
|
bool isCapacityReserved;
|
||||||
bool isSharable;
|
bool isSharable;
|
||||||
const QArrayData *commonEmpty;
|
const QArrayData *commonEmpty;
|
||||||
@ -603,7 +603,7 @@ void tst_QArrayData::allocate()
|
|||||||
{
|
{
|
||||||
QFETCH(size_t, objectSize);
|
QFETCH(size_t, objectSize);
|
||||||
QFETCH(size_t, alignment);
|
QFETCH(size_t, alignment);
|
||||||
QFETCH(QArrayData::AllocateOptions, allocateOptions);
|
QFETCH(QArrayData::AllocationOptions, allocateOptions);
|
||||||
QFETCH(bool, isCapacityReserved);
|
QFETCH(bool, isCapacityReserved);
|
||||||
QFETCH(bool, isSharable);
|
QFETCH(bool, isSharable);
|
||||||
QFETCH(const QArrayData *, commonEmpty);
|
QFETCH(const QArrayData *, commonEmpty);
|
||||||
@ -614,14 +614,14 @@ void tst_QArrayData::allocate()
|
|||||||
|
|
||||||
// Shared Empty
|
// Shared Empty
|
||||||
QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0,
|
QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0,
|
||||||
QArrayData::AllocateOptions(allocateOptions)), commonEmpty);
|
QArrayData::AllocationOptions(allocateOptions)), commonEmpty);
|
||||||
|
|
||||||
Deallocator keeper(objectSize, minAlignment);
|
Deallocator keeper(objectSize, minAlignment);
|
||||||
keeper.headers.reserve(1024);
|
keeper.headers.reserve(1024);
|
||||||
|
|
||||||
for (int capacity = 1; capacity <= 1024; capacity <<= 1) {
|
for (int capacity = 1; capacity <= 1024; capacity <<= 1) {
|
||||||
QArrayData *data = QArrayData::allocate(objectSize, minAlignment,
|
QArrayData *data = QArrayData::allocate(objectSize, minAlignment,
|
||||||
capacity, QArrayData::AllocateOptions(allocateOptions));
|
capacity, QArrayData::AllocationOptions(allocateOptions));
|
||||||
keeper.headers.append(data);
|
keeper.headers.append(data);
|
||||||
|
|
||||||
QCOMPARE(data->size, 0);
|
QCOMPARE(data->size, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user