diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-06-11 19:42:05 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-08 10:29:09 +0100 |
commit | 62c673ccc6f81cee09a25f5acceec2768cea4672 (patch) | |
tree | 883720fc4a6d333dbf3afb7b8276bbd33d202ffc /src/corelib/tools/qarraydata.h | |
parent | a3aa2fcfa72ab69bdbded26dcd43e37b35796a17 (diff) |
Add reference-count manipulation functions to QArrayData and hide ref
The next change will stop using some values in the reference counter as
settings from the data.
Change-Id: I94df1fe643896373fac2f000fff55bc7708fc807
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 8c21fd55c8..183cf9f002 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -67,7 +67,7 @@ struct Q_CORE_EXPORT QArrayData }; Q_DECLARE_FLAGS(ArrayOptions, ArrayOption) - QtPrivate::RefCount ref; + QtPrivate::RefCount ref_; uint flags; int size; uint alloc; @@ -84,6 +84,16 @@ struct Q_CORE_EXPORT QArrayData return alloc; } + bool ref() + { + return ref_.ref(); + } + + bool deref() + { + return ref_.deref(); + } + void *data() { Q_ASSERT(size == 0 @@ -106,13 +116,23 @@ struct Q_CORE_EXPORT QArrayData return flags & Mutable; } + bool isStatic() const + { + return ref_.isStatic(); + } + + bool isShared() const + { + return ref_.isShared(); + } + // Returns true if a detach is necessary before modifying the data // This method is intentionally not const: if you want to know whether // detaching is necessary, you should be in a non-const function already bool needsDetach() { // ### optimize me -- this currently requires 3 conditionals! - return !isMutable() || ref.isShared(); + return !isMutable() || isShared(); } size_t detachCapacity(size_t newSize) const @@ -290,7 +310,7 @@ struct QTypedArrayData Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); QTypedArrayData *result = static_cast<QTypedArrayData *>(prepareRawData(options)); if (result) { - Q_ASSERT(!result->ref.isShared()); // No shared empty, please! + Q_ASSERT(!result->isShared()); // No shared empty, please! result->offset = reinterpret_cast<const char *>(data) - reinterpret_cast<const char *>(result); |