Deprecate setSharable in Qt containers
The ability to set a container to be unsharable has very little use and it costs us an extra conditional for every refcount up and possibly down. This change is a no-op for current Qt 5. It shuffles a few things around just so Qt can compile if you define QT_NO_UNSHARABLE_CONTAINERS. That is done to ease the fixing of the code in Qt 6 and to make my life easier: I'll keep that defined in my local Qt build so I can catch any misuses of this deprecated API. The newly deprecated methods are not marked QT_DEPRECATED because the bootstrapped tools wouldn't build -- they're built with QT_NO_DEPRECATED defined, which causes build errors. [ChangeLog][QtCore] The setSharable() and isSharable() functions in Qt containers has been deprecated and will be removed in Qt 6. New applications should not use this feature, while old applications that may be using this (undocumented) feature should port away from it. Discussed-on: http://lists.qt-project.org/pipermail/development/2014-February/015724.html Change-Id: I789771743dcaed6a43eccd99382f8b3ffa61e479 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
cafa3848e2
commit
e57b521d95
@ -58,7 +58,10 @@
|
||||
#if !defined(QT_BUILD_QMAKE) && !defined(QT_BUILD_CONFIGURE)
|
||||
#include <QtCore/qconfig.h>
|
||||
#include <QtCore/qfeatures.h>
|
||||
#endif
|
||||
#define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
# define QT_NO_UNSHARABLE_CONTAINERS
|
||||
#endif
|
||||
|
||||
/* These two macros makes it possible to turn the builtin line expander into a
|
||||
|
@ -75,10 +75,13 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
|
||||
&& !(alignment & (alignment - 1)));
|
||||
|
||||
// Don't allocate empty headers
|
||||
if (!(options & RawData) && !capacity)
|
||||
return !(options & Unsharable)
|
||||
? const_cast<QArrayData *>(&qt_array_empty)
|
||||
: const_cast<QArrayData *>(&qt_array_unsharable_empty);
|
||||
if (!(options & RawData) && !capacity) {
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (options & Unsharable)
|
||||
return const_cast<QArrayData *>(&qt_array_unsharable_empty);
|
||||
#endif
|
||||
return const_cast<QArrayData *>(&qt_array_empty);
|
||||
}
|
||||
|
||||
size_t headerSize = sizeof(QArrayData);
|
||||
|
||||
@ -118,8 +121,10 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
|
||||
&& !(alignment & (alignment - 1)));
|
||||
Q_UNUSED(objectSize) Q_UNUSED(alignment)
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (data == &qt_array_unsharable_empty)
|
||||
return;
|
||||
#endif
|
||||
|
||||
Q_ASSERT_X(!data->ref.isStatic(), "QArrayData::deallocate", "Static data can not be deleted");
|
||||
::free(data);
|
||||
|
@ -80,7 +80,9 @@ struct Q_CORE_EXPORT QArrayData
|
||||
|
||||
enum AllocationOption {
|
||||
CapacityReserved = 0x1,
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
Unsharable = 0x2,
|
||||
#endif
|
||||
RawData = 0x4,
|
||||
Grow = 0x8,
|
||||
|
||||
@ -99,8 +101,10 @@ struct Q_CORE_EXPORT QArrayData
|
||||
AllocationOptions detachFlags() const
|
||||
{
|
||||
AllocationOptions result;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (!ref.isSharable())
|
||||
result |= Unsharable;
|
||||
#endif
|
||||
if (capacityReserved)
|
||||
result |= CapacityReserved;
|
||||
return result;
|
||||
|
@ -134,6 +134,7 @@ public:
|
||||
return (!d->isMutable() || d->ref.isShared());
|
||||
}
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
void setSharable(bool sharable)
|
||||
{
|
||||
if (needsDetach()) {
|
||||
@ -147,6 +148,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool isSharable() const { return d->isSharable(); }
|
||||
#endif
|
||||
|
||||
void swap(QArrayDataPointer &other)
|
||||
{
|
||||
qSwap(d, other.d);
|
||||
|
@ -104,7 +104,9 @@ public:
|
||||
|
||||
inline void detach() { if (d->ref.load() != 1) detach_helper(); }
|
||||
inline bool isDetached() const { return d->ref.load() == 1; }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
|
||||
#endif
|
||||
|
||||
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
|
@ -330,7 +330,9 @@ public:
|
||||
|
||||
inline void detach() { if (d->ref.isShared()) detach_helper(); }
|
||||
inline bool isDetached() const { return !d->ref.isShared(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QHashData::shared_null) d->sharable = sharable; }
|
||||
#endif
|
||||
inline bool isSharedWith(const QHash<Key, T> &other) const { return d == other.d; }
|
||||
|
||||
void clear();
|
||||
|
@ -106,7 +106,9 @@ public:
|
||||
inline void detach()
|
||||
{ if (d->ref.isShared()) detach_helper2(this->e); }
|
||||
inline bool isDetached() const { return !d->ref.isShared(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QLinkedListData::shared_null) d->sharable = sharable; }
|
||||
#endif
|
||||
inline bool isSharedWith(const QLinkedList<T> &other) const { return d == other.d; }
|
||||
|
||||
inline bool isEmpty() const { return d->size == 0; }
|
||||
|
@ -146,6 +146,7 @@ public:
|
||||
}
|
||||
|
||||
inline bool isDetached() const { return !d->ref.isShared(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable)
|
||||
{
|
||||
if (sharable == d->ref.isSharable())
|
||||
@ -155,6 +156,7 @@ public:
|
||||
if (d != &QListData::shared_null)
|
||||
d->ref.setSharable(sharable);
|
||||
}
|
||||
#endif
|
||||
inline bool isSharedWith(const QList<T> &other) const { return d == other.d; }
|
||||
|
||||
inline bool isEmpty() const { return p.isEmpty(); }
|
||||
|
@ -377,6 +377,7 @@ public:
|
||||
|
||||
inline void detach() { if (d->ref.isShared()) detach_helper(); }
|
||||
inline bool isDetached() const { return !d->ref.isShared(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable)
|
||||
{
|
||||
if (sharable == d->ref.isSharable())
|
||||
@ -386,6 +387,7 @@ public:
|
||||
// Don't call on shared_null
|
||||
d->ref.setSharable(sharable);
|
||||
}
|
||||
#endif
|
||||
inline bool isSharedWith(const QMap<Key, T> &other) const { return d == other.d; }
|
||||
|
||||
void clear();
|
||||
|
@ -55,8 +55,10 @@ class RefCount
|
||||
public:
|
||||
inline bool ref() Q_DECL_NOTHROW {
|
||||
int count = atomic.load();
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (count == 0) // !isSharable
|
||||
return false;
|
||||
#endif
|
||||
if (count != -1) // !isStatic
|
||||
atomic.ref();
|
||||
return true;
|
||||
@ -64,13 +66,16 @@ public:
|
||||
|
||||
inline bool deref() Q_DECL_NOTHROW {
|
||||
int count = atomic.load();
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (count == 0) // !isSharable
|
||||
return false;
|
||||
#endif
|
||||
if (count == -1) // isStatic
|
||||
return true;
|
||||
return atomic.deref();
|
||||
}
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
bool setSharable(bool sharable) Q_DECL_NOTHROW
|
||||
{
|
||||
Q_ASSERT(!isShared());
|
||||
@ -80,17 +85,18 @@ public:
|
||||
return atomic.testAndSetRelaxed(1, 0);
|
||||
}
|
||||
|
||||
bool isStatic() const Q_DECL_NOTHROW
|
||||
{
|
||||
// Persistent object, never deleted
|
||||
return atomic.load() == -1;
|
||||
}
|
||||
|
||||
bool isSharable() const Q_DECL_NOTHROW
|
||||
{
|
||||
// Sharable === Shared ownership.
|
||||
return atomic.load() != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isStatic() const Q_DECL_NOTHROW
|
||||
{
|
||||
// Persistent object, never deleted
|
||||
return atomic.load() == -1;
|
||||
}
|
||||
|
||||
bool isShared() const Q_DECL_NOTHROW
|
||||
{
|
||||
|
@ -91,7 +91,9 @@ public:
|
||||
|
||||
inline void detach() { q_hash.detach(); }
|
||||
inline bool isDetached() const { return q_hash.isDetached(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable) { q_hash.setSharable(sharable); }
|
||||
#endif
|
||||
|
||||
inline void clear() { q_hash.clear(); }
|
||||
|
||||
|
@ -107,6 +107,7 @@ public:
|
||||
|
||||
inline void detach();
|
||||
inline bool isDetached() const { return !d->ref.isShared(); }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
inline void setSharable(bool sharable)
|
||||
{
|
||||
if (sharable == d->ref.isSharable())
|
||||
@ -122,6 +123,7 @@ public:
|
||||
}
|
||||
Q_ASSERT(d->ref.isSharable() == sharable);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline bool isSharedWith(const QVector<T> &other) const { return d == other.d; }
|
||||
|
||||
@ -329,10 +331,12 @@ template <typename T>
|
||||
void QVector<T>::detach()
|
||||
{
|
||||
if (!isDetached()) {
|
||||
if (d->alloc)
|
||||
reallocData(d->size, int(d->alloc));
|
||||
else
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
if (!d->alloc)
|
||||
d = Data::unsharableEmpty();
|
||||
else
|
||||
#endif
|
||||
reallocData(d->size, int(d->alloc));
|
||||
}
|
||||
Q_ASSERT(isDetached());
|
||||
}
|
||||
@ -484,7 +488,9 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
|
||||
x = Data::allocate(aalloc, options);
|
||||
Q_CHECK_PTR(x);
|
||||
// aalloc is bigger then 0 so it is not [un]sharedEmpty
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
Q_ASSERT(x->ref.isSharable() || options.testFlag(QArrayData::Unsharable));
|
||||
#endif
|
||||
Q_ASSERT(!x->ref.isStatic());
|
||||
x->size = asize;
|
||||
|
||||
@ -550,7 +556,9 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
|
||||
|
||||
Q_ASSERT(d->data());
|
||||
Q_ASSERT(uint(d->size) <= d->alloc);
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
Q_ASSERT(d != Data::unsharableEmpty());
|
||||
#endif
|
||||
Q_ASSERT(aalloc ? d != Data::sharedNull() : d == Data::sharedNull());
|
||||
Q_ASSERT(d->alloc >= uint(aalloc));
|
||||
Q_ASSERT(d->size == asize);
|
||||
|
@ -101,9 +101,10 @@ public:
|
||||
bool isStatic() const { return d->ref.isStatic(); }
|
||||
bool isShared() const { return d->ref.isShared(); }
|
||||
bool isSharedWith(const SimpleVector &other) const { return d == other.d; }
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
bool isSharable() const { return d->ref.isSharable(); }
|
||||
|
||||
void setSharable(bool sharable) { d.setSharable(sharable); }
|
||||
#endif
|
||||
|
||||
size_t size() const { return d->size; }
|
||||
size_t capacity() const { return d->alloc; }
|
||||
|
@ -52,7 +52,9 @@ struct SharedNullVerifier
|
||||
{
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isStatic());
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isShared());
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
Q_ASSERT(QArrayData::shared_null[0].ref.isSharable());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@ -107,7 +109,9 @@ void tst_QArrayData::referenceCounting()
|
||||
QCOMPARE(array.ref.atomic.load(), 1);
|
||||
|
||||
QVERIFY(!array.ref.isStatic());
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(array.ref.isSharable());
|
||||
#endif
|
||||
|
||||
QVERIFY(array.ref.ref());
|
||||
QCOMPARE(array.ref.atomic.load(), 2);
|
||||
@ -127,6 +131,7 @@ void tst_QArrayData::referenceCounting()
|
||||
// Now would be a good time to free/release allocated data
|
||||
}
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
{
|
||||
// Reference counting initialized to 0 (non-sharable)
|
||||
QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
|
||||
@ -145,6 +150,7 @@ void tst_QArrayData::referenceCounting()
|
||||
|
||||
// Free/release data
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
// Reference counting initialized to -1 (static read-only data)
|
||||
@ -153,13 +159,16 @@ void tst_QArrayData::referenceCounting()
|
||||
QCOMPARE(array.ref.atomic.load(), -1);
|
||||
|
||||
QVERIFY(array.ref.isStatic());
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(array.ref.isSharable());
|
||||
#endif
|
||||
|
||||
QVERIFY(array.ref.ref());
|
||||
QCOMPARE(array.ref.atomic.load(), -1);
|
||||
|
||||
QVERIFY(array.ref.deref());
|
||||
QCOMPARE(array.ref.atomic.load(), -1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,16 +178,19 @@ void tst_QArrayData::sharedNullEmpty()
|
||||
QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0);
|
||||
|
||||
QVERIFY(null->ref.isStatic());
|
||||
QVERIFY(null->ref.isSharable());
|
||||
QVERIFY(null->ref.isShared());
|
||||
|
||||
QVERIFY(empty->ref.isStatic());
|
||||
QVERIFY(empty->ref.isSharable());
|
||||
QVERIFY(empty->ref.isShared());
|
||||
|
||||
QCOMPARE(null->ref.atomic.load(), -1);
|
||||
QCOMPARE(empty->ref.atomic.load(), -1);
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(null->ref.isSharable());
|
||||
QVERIFY(empty->ref.isSharable());
|
||||
#endif
|
||||
|
||||
QVERIFY(null->ref.ref());
|
||||
QVERIFY(empty->ref.ref());
|
||||
|
||||
@ -305,6 +317,7 @@ void tst_QArrayData::simpleVector()
|
||||
QVERIFY(!v7.isShared());
|
||||
QVERIFY(!v8.isShared());
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(v1.isSharable());
|
||||
QVERIFY(v2.isSharable());
|
||||
QVERIFY(v3.isSharable());
|
||||
@ -313,6 +326,7 @@ void tst_QArrayData::simpleVector()
|
||||
QVERIFY(v6.isSharable());
|
||||
QVERIFY(v7.isSharable());
|
||||
QVERIFY(v8.isSharable());
|
||||
#endif
|
||||
|
||||
QVERIFY(v1.isSharedWith(v2));
|
||||
QVERIFY(v1.isSharedWith(v3));
|
||||
@ -496,6 +510,7 @@ void tst_QArrayData::simpleVector()
|
||||
for (int i = 0; i < 120; ++i)
|
||||
QCOMPARE(v1[i], v8[i % 10]);
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
{
|
||||
v7.setSharable(true);
|
||||
QVERIFY(v7.isSharable());
|
||||
@ -558,6 +573,7 @@ void tst_QArrayData::simpleVector()
|
||||
QVERIFY(null.isEmpty());
|
||||
QVERIFY(empty.isEmpty());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(SimpleVector<int>)
|
||||
@ -648,7 +664,7 @@ void tst_QArrayData::allocate_data()
|
||||
QTest::addColumn<size_t>("alignment");
|
||||
QTest::addColumn<QArrayData::AllocationOptions>("allocateOptions");
|
||||
QTest::addColumn<bool>("isCapacityReserved");
|
||||
QTest::addColumn<bool>("isSharable");
|
||||
QTest::addColumn<bool>("isSharable"); // ### Qt6: remove
|
||||
QTest::addColumn<const QArrayData *>("commonEmpty");
|
||||
|
||||
struct {
|
||||
@ -662,10 +678,12 @@ void tst_QArrayData::allocate_data()
|
||||
};
|
||||
|
||||
QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0);
|
||||
QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
|
||||
|
||||
QVERIFY(shared_empty);
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
|
||||
QVERIFY(unsharable_empty);
|
||||
#endif
|
||||
|
||||
struct {
|
||||
char const *description;
|
||||
@ -676,10 +694,12 @@ void tst_QArrayData::allocate_data()
|
||||
} options[] = {
|
||||
{ "Default", QArrayData::Default, false, true, shared_empty },
|
||||
{ "Reserved", QArrayData::CapacityReserved, true, true, shared_empty },
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
{ "Reserved | Unsharable",
|
||||
QArrayData::CapacityReserved | QArrayData::Unsharable, true, false,
|
||||
unsharable_empty },
|
||||
{ "Unsharable", QArrayData::Unsharable, false, false, unsharable_empty },
|
||||
#endif
|
||||
{ "Grow", QArrayData::Grow, false, true, shared_empty }
|
||||
};
|
||||
|
||||
@ -700,7 +720,6 @@ void tst_QArrayData::allocate()
|
||||
QFETCH(size_t, alignment);
|
||||
QFETCH(QArrayData::AllocationOptions, allocateOptions);
|
||||
QFETCH(bool, isCapacityReserved);
|
||||
QFETCH(bool, isSharable);
|
||||
QFETCH(const QArrayData *, commonEmpty);
|
||||
|
||||
// Minimum alignment that can be requested is that of QArrayData.
|
||||
@ -725,7 +744,10 @@ void tst_QArrayData::allocate()
|
||||
else
|
||||
QCOMPARE(data->alloc, uint(capacity));
|
||||
QCOMPARE(data->capacityReserved, uint(isCapacityReserved));
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QFETCH(bool, isSharable);
|
||||
QCOMPARE(data->ref.isSharable(), isSharable);
|
||||
#endif
|
||||
|
||||
// Check that the allocated array can be used. Best tested with a
|
||||
// memory checker, such as valgrind, running.
|
||||
@ -1302,6 +1324,7 @@ static inline bool arrayIsFilledWith(const QArrayDataPointer<int> &array,
|
||||
|
||||
void tst_QArrayData::setSharable_data()
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QTest::addColumn<QArrayDataPointer<int> >("array");
|
||||
QTest::addColumn<size_t>("size");
|
||||
QTest::addColumn<size_t>("capacity");
|
||||
@ -1342,10 +1365,12 @@ void tst_QArrayData::setSharable_data()
|
||||
QTest::newRow("non-empty-reserved") << nonEmptyReserved << size_t(7) << size_t(15) << true << 2;
|
||||
QTest::newRow("static-array") << staticArray << size_t(10) << size_t(0) << false << 3;
|
||||
QTest::newRow("raw-data") << rawData << size_t(10) << size_t(0) << false << 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QArrayData::setSharable()
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QFETCH(QArrayDataPointer<int>, array);
|
||||
QFETCH(size_t, size);
|
||||
QFETCH(size_t, capacity);
|
||||
@ -1424,6 +1449,7 @@ void tst_QArrayData::setSharable()
|
||||
|
||||
QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved));
|
||||
QVERIFY(array->ref.isSharable());
|
||||
#endif
|
||||
}
|
||||
|
||||
struct ResetOnDtor
|
||||
@ -1474,6 +1500,7 @@ void fromRawData_impl()
|
||||
QVERIFY((const T *)raw.constBegin() != array);
|
||||
}
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
{
|
||||
// Immutable, unsharable
|
||||
SimpleVector<T> raw = SimpleVector<T>::fromRawData(array,
|
||||
@ -1502,6 +1529,7 @@ void fromRawData_impl()
|
||||
QCOMPARE(raw.back(), T(11));
|
||||
QVERIFY((const T *)raw.constBegin() != array);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QArrayData::fromRawData_data()
|
||||
@ -1558,7 +1586,9 @@ void tst_QArrayData::literals()
|
||||
QVERIFY(v.isStatic());
|
||||
#endif
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(v.isSharable());
|
||||
#endif
|
||||
QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd());
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -1607,7 +1637,9 @@ void tst_QArrayData::variadicLiterals()
|
||||
|
||||
QVERIFY(v.isStatic());
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QVERIFY(v.isSharable());
|
||||
#endif
|
||||
QCOMPARE((const int *)(v.constBegin() + v.size()), (const int *)v.constEnd());
|
||||
|
||||
for (int i = 0; i < 7; ++i)
|
||||
|
@ -1217,12 +1217,14 @@ void tst_QHash::noNeedlessRehashes()
|
||||
|
||||
void tst_QHash::const_shared_null()
|
||||
{
|
||||
QHash<int, QString> hash2;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QHash<int, QString> hash1;
|
||||
hash1.setSharable(false);
|
||||
QVERIFY(hash1.isDetached());
|
||||
|
||||
QHash<int, QString> hash2;
|
||||
hash2.setSharable(true);
|
||||
#endif
|
||||
QVERIFY(!hash2.isDetached());
|
||||
}
|
||||
|
||||
|
@ -1018,12 +1018,14 @@ void tst_QLinkedList::initializeList() const
|
||||
template<typename T>
|
||||
void tst_QLinkedList::constSharedNull() const
|
||||
{
|
||||
QLinkedList<T> list2;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QLinkedList<T> list1;
|
||||
list1.setSharable(false);
|
||||
QVERIFY(list1.isDetached());
|
||||
|
||||
QLinkedList<T> list2;
|
||||
list2.setSharable(true);
|
||||
#endif
|
||||
QVERIFY(!list2.isDetached());
|
||||
}
|
||||
|
||||
@ -1049,6 +1051,7 @@ void tst_QLinkedList::constSharedNullComplex() const
|
||||
|
||||
void tst_QLinkedList::setSharableInt() const
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QLinkedList<int> orglist;
|
||||
orglist << 0 << 1 << 2 << 3 << 4 << 5;
|
||||
int size = 6;
|
||||
@ -1094,6 +1097,7 @@ void tst_QLinkedList::setSharableInt() const
|
||||
}
|
||||
|
||||
QCOMPARE(list.size(), size);
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QLinkedList)
|
||||
|
@ -1522,12 +1522,14 @@ void tst_QList::initializeList() const
|
||||
template<typename T>
|
||||
void tst_QList::constSharedNull() const
|
||||
{
|
||||
QList<T> list2;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QList<T> list1;
|
||||
list1.setSharable(false);
|
||||
QVERIFY(list1.isDetached());
|
||||
|
||||
QList<T> list2;
|
||||
list2.setSharable(true);
|
||||
#endif
|
||||
QVERIFY(!list2.isDetached());
|
||||
}
|
||||
|
||||
@ -1553,16 +1555,19 @@ void tst_QList::constSharedNullComplex() const
|
||||
template <class T>
|
||||
void generateSetSharableData()
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QTest::addColumn<QList<T> >("list");
|
||||
QTest::addColumn<int>("size");
|
||||
|
||||
QTest::newRow("null") << QList<T>() << 0;
|
||||
QTest::newRow("non-empty") << (QList<T>() << T(0) << T(1) << T(2) << T(3) << T(4)) << 5;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void runSetSharableTest()
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QFETCH(QList<T>, list);
|
||||
QFETCH(int, size);
|
||||
|
||||
@ -1602,6 +1607,7 @@ void runSetSharableTest()
|
||||
QCOMPARE(int(list[i]), i);
|
||||
|
||||
QCOMPARE(list.size(), size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QList::setSharableInt_data() const
|
||||
|
@ -984,12 +984,14 @@ void tst_QMap::qmultimap_specific()
|
||||
|
||||
void tst_QMap::const_shared_null()
|
||||
{
|
||||
QMap<int, QString> map2;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QMap<int, QString> map1;
|
||||
map1.setSharable(false);
|
||||
QVERIFY(map1.isDetached());
|
||||
|
||||
QMap<int, QString> map2;
|
||||
map2.setSharable(true);
|
||||
#endif
|
||||
QVERIFY(!map2.isDetached());
|
||||
}
|
||||
|
||||
@ -1046,6 +1048,7 @@ const T &const_(const T &t)
|
||||
|
||||
void tst_QMap::setSharable()
|
||||
{
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
QMap<int, QString> map;
|
||||
|
||||
map.insert(1, "um");
|
||||
@ -1095,6 +1098,7 @@ void tst_QMap::setSharable()
|
||||
QVERIFY(!map.isDetached());
|
||||
QVERIFY(copy.isSharedWith(map));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QMap::insert()
|
||||
@ -1204,7 +1208,6 @@ void tst_QMap::initializerList()
|
||||
void tst_QMap::testInsertWithHint()
|
||||
{
|
||||
QMap<int, int> map;
|
||||
map.setSharable(false);
|
||||
|
||||
// Check with end hint();
|
||||
map.insert(map.constEnd(), 3, 1); // size == 1
|
||||
@ -1268,7 +1271,6 @@ void tst_QMap::testInsertWithHint()
|
||||
void tst_QMap::testInsertMultiWithHint()
|
||||
{
|
||||
QMap<int, int> map;
|
||||
map.setSharable(false);
|
||||
|
||||
typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS
|
||||
map.insertMulti(cite(map.end()), 64, 65);
|
||||
|
@ -265,12 +265,15 @@ private slots:
|
||||
void initializeListCustom();
|
||||
|
||||
void const_shared_null();
|
||||
#if 1
|
||||
// ### Qt6 remove this section
|
||||
void setSharableInt_data();
|
||||
void setSharableInt();
|
||||
void setSharableMovable_data();
|
||||
void setSharableMovable();
|
||||
void setSharableCustom_data();
|
||||
void setSharableCustom();
|
||||
#endif
|
||||
|
||||
void detachInt() const;
|
||||
void detachMovable() const;
|
||||
@ -393,6 +396,14 @@ void tst_QVector::copyConstructor() const
|
||||
QVector<T> v2(v1);
|
||||
QCOMPARE(v1, v2);
|
||||
}
|
||||
{
|
||||
QVector<T> v1;
|
||||
v1 << value1 << value2 << value3 << value4;
|
||||
QVector<T> v2(v1);
|
||||
QCOMPARE(v1, v2);
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v1;
|
||||
v1.setSharable(false);
|
||||
@ -400,12 +411,6 @@ void tst_QVector::copyConstructor() const
|
||||
QVERIFY(!v1.isSharedWith(v2));
|
||||
QCOMPARE(v1, v2);
|
||||
}
|
||||
{
|
||||
QVector<T> v1;
|
||||
v1 << value1 << value2 << value3 << value4;
|
||||
QVector<T> v2(v1);
|
||||
QCOMPARE(v1, v2);
|
||||
}
|
||||
{
|
||||
QVector<T> v1;
|
||||
v1 << value1 << value2 << value3 << value4;
|
||||
@ -414,6 +419,7 @@ void tst_QVector::copyConstructor() const
|
||||
QVERIFY(!v1.isSharedWith(v2));
|
||||
QCOMPARE(v1, v2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::copyConstructorInt() const
|
||||
@ -514,6 +520,8 @@ void tst_QVector::append() const
|
||||
QVERIFY(v.size() == 3);
|
||||
QCOMPARE(v.at(v.size() - 1), SimpleValue<T>::at(0));
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v(2);
|
||||
v.reserve(12);
|
||||
@ -522,6 +530,7 @@ void tst_QVector::append() const
|
||||
QVERIFY(v.size() == 3);
|
||||
QCOMPARE(v.last(), SimpleValue<T>::at(0));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::appendInt() const
|
||||
@ -819,12 +828,15 @@ void tst_QVector::eraseEmpty() const
|
||||
v.erase(v.begin(), v.end());
|
||||
QCOMPARE(v.size(), 0);
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v;
|
||||
v.setSharable(false);
|
||||
v.erase(v.begin(), v.end());
|
||||
QCOMPARE(v.size(), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::eraseEmptyInt() const
|
||||
@ -855,6 +867,8 @@ void tst_QVector::eraseEmptyReserved() const
|
||||
v.erase(v.begin(), v.end());
|
||||
QCOMPARE(v.size(), 0);
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v;
|
||||
v.reserve(10);
|
||||
@ -862,6 +876,7 @@ void tst_QVector::eraseEmptyReserved() const
|
||||
v.erase(v.begin(), v.end());
|
||||
QCOMPARE(v.size(), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::eraseEmptyReservedInt() const
|
||||
@ -968,6 +983,8 @@ void tst_QVector::erase(bool shared) const
|
||||
if (shared)
|
||||
QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v = SimpleValue<T>::vector(10);
|
||||
SharedVectorChecker<T> svc(v, shared);
|
||||
@ -980,6 +997,7 @@ void tst_QVector::erase(bool shared) const
|
||||
if (shared)
|
||||
QCOMPARE(SimpleValue<T>::vector(10), *svc.copy);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::eraseInt() const
|
||||
@ -1052,6 +1070,8 @@ template<typename T> void tst_QVector::eraseReserved() const
|
||||
v.erase(v.begin() + 1, v.end() - 1);
|
||||
QCOMPARE(v.size(), 2);
|
||||
}
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
{
|
||||
QVector<T> v(10);
|
||||
v.reserve(16);
|
||||
@ -1061,6 +1081,7 @@ template<typename T> void tst_QVector::eraseReserved() const
|
||||
v.erase(v.begin(), v.end() - 1);
|
||||
QCOMPARE(v.size(), 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::eraseReservedInt() const
|
||||
@ -1512,6 +1533,14 @@ void tst_QVector::resizePOD_data() const
|
||||
QVERIFY(emptyReserved.capacity() >= 10);
|
||||
QVERIFY(nonEmptyReserved.capacity() >= 15);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
QVector<int> nullNotShared;
|
||||
QVector<int> emptyNotShared(0, 5);
|
||||
QVector<int> emptyReservedNotShared;
|
||||
@ -1530,16 +1559,12 @@ void tst_QVector::resizePOD_data() const
|
||||
nonEmptyNotShared.setSharable(false);
|
||||
nonEmptyReservedNotShared.setSharable(false);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
QTest::newRow("nullNotShared") << nullNotShared << 10;
|
||||
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
|
||||
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
|
||||
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
|
||||
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::resizePOD() const
|
||||
@ -1583,6 +1608,14 @@ void tst_QVector::resizeComplexMovable_data() const
|
||||
QVERIFY(emptyReserved.capacity() >= 10);
|
||||
QVERIFY(nonEmptyReserved.capacity() >= 15);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
QVector<Movable> nullNotShared;
|
||||
QVector<Movable> emptyNotShared(0, 'Q');
|
||||
QVector<Movable> emptyReservedNotShared;
|
||||
@ -1601,16 +1634,12 @@ void tst_QVector::resizeComplexMovable_data() const
|
||||
nonEmptyNotShared.setSharable(false);
|
||||
nonEmptyReservedNotShared.setSharable(false);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
QTest::newRow("nullNotShared") << nullNotShared << 10;
|
||||
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
|
||||
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
|
||||
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
|
||||
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::resizeComplexMovable() const
|
||||
@ -1658,6 +1687,14 @@ void tst_QVector::resizeComplex_data() const
|
||||
QVERIFY(emptyReserved.capacity() >= 10);
|
||||
QVERIFY(nonEmptyReserved.capacity() >= 15);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
QVector<Custom> nullNotShared;
|
||||
QVector<Custom> emptyNotShared(0, '0');
|
||||
QVector<Custom> emptyReservedNotShared;
|
||||
@ -1676,16 +1713,12 @@ void tst_QVector::resizeComplex_data() const
|
||||
nonEmptyNotShared.setSharable(false);
|
||||
nonEmptyReservedNotShared.setSharable(false);
|
||||
|
||||
QTest::newRow("null") << null << 10;
|
||||
QTest::newRow("empty") << empty << 10;
|
||||
QTest::newRow("emptyReserved") << emptyReserved << 10;
|
||||
QTest::newRow("nonEmpty") << nonEmpty << 10;
|
||||
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
|
||||
QTest::newRow("nullNotShared") << nullNotShared << 10;
|
||||
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
|
||||
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
|
||||
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
|
||||
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QVector::resizeComplex() const
|
||||
@ -2070,15 +2103,20 @@ void tst_QVector::initializeListCustom()
|
||||
|
||||
void tst_QVector::const_shared_null()
|
||||
{
|
||||
QVector<int> v2;
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
QVector<int> v1;
|
||||
v1.setSharable(false);
|
||||
QVERIFY(v1.isDetached());
|
||||
|
||||
QVector<int> v2;
|
||||
v2.setSharable(true);
|
||||
#endif
|
||||
QVERIFY(!v2.isDetached());
|
||||
}
|
||||
|
||||
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
|
||||
// ### Qt6 remove this section
|
||||
template<typename T>
|
||||
void tst_QVector::setSharable_data() const
|
||||
{
|
||||
@ -2109,21 +2147,6 @@ void tst_QVector::setSharable_data() const
|
||||
QTest::newRow("non-empty, Reserved") << nonEmptyReserved << 7 << 15 << true;
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableInt_data()
|
||||
{
|
||||
setSharable_data<int>();
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableMovable_data()
|
||||
{
|
||||
setSharable_data<Movable>();
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableCustom_data()
|
||||
{
|
||||
setSharable_data<Custom>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void tst_QVector::setSharable() const
|
||||
{
|
||||
@ -2185,6 +2208,30 @@ void tst_QVector::setSharable() const
|
||||
.arg(vector.capacity())
|
||||
.arg(capacity)));
|
||||
}
|
||||
#else
|
||||
template<typename T> void tst_QVector::setSharable_data() const
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T> void tst_QVector::setSharable() const
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QVector::setSharableInt_data()
|
||||
{
|
||||
setSharable_data<int>();
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableMovable_data()
|
||||
{
|
||||
setSharable_data<Movable>();
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableCustom_data()
|
||||
{
|
||||
setSharable_data<Custom>();
|
||||
}
|
||||
|
||||
void tst_QVector::setSharableInt()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user