diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.cpp | 13 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qcontiguouscache.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qrefcount.h | 18 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 14 |
11 files changed, 52 insertions, 13 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 825b3289c7..12736d5c2e 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -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); diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index ffb2b8765e..10a9e35542 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -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; diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 533f7a306f..2245106ec0 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -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); diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index d601ddb819..e05ef33aa2 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -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 diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 40e501355c..f68b02be2c 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -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(); diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index bdacdbcd26..3377d1bbc3 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -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; } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 3a0d01aa8d..9e4ba70908 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -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(); } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 487039ccfb..76f8bd6f17 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -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(); diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h index 84314b1fcc..3a8f0f3982 100644 --- a/src/corelib/tools/qrefcount.h +++ b/src/corelib/tools/qrefcount.h @@ -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 { diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index ad2f91b983..0cc704b6cf 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -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(); } diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index b0be98c296..6f7c534085 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -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); |