summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-02-16 23:28:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-02 16:34:21 +0200
commit5e82bb9e6fe71fda6befecf6019e8248846a3fda (patch)
treeb9fc62a6af2f34795ff35443d2ee884b523eec4b /tests/auto/corelib/tools/qarraydata
parent15e3ae6b9da9b32236d3e3348ede86c3acf06fb4 (diff)
Introduce QArrayDataPointer::needsDetach
While QArrayDataPointer offers generic detach() functionality, this is only useful for operations that may modify data, but don't otherwise affect the container itself, such as non-const iteration, front() and back(). For other modifying operations, users of the API typically need to decide whether a detach is needed based on QArrayData's requirements (is data mutable? is it currently shared?) and its own (do we have spare capacity for growth?). Now that data may be shared, static or otherwise immutable (e.g., fromRawData) it no longer suffices to check the ref-count for isShared(). This commit adds needsDetach() which, from the point-of-view of QArrayData(Pointer), answers the question: 'Can contained data and associated metadata be changed?'. This fixes QArrayDataPointer::setSharable for static data (e.g., Q_ARRAY_LITERAL), previously it only catered to shared_null. SimpleVector is also fixed since it wasn't checking Mutability and it needs to because it supports fromRawData(). Change-Id: I3c7f9c85c83dfd02333762852fa456208e96d5ad Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata')
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 641516e0d0..7e679704c8 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -175,7 +175,7 @@ public:
if (size() == newSize)
return;
- if (d->ref.isShared() || newSize > capacity()) {
+ if (d.needsDetach() || newSize > capacity()) {
SimpleVector detached(Data::allocate(
d->detachCapacity(newSize), d->detachFlags()));
if (newSize) {
@@ -211,7 +211,7 @@ public:
return;
T *const begin = d->begin();
- if (d->ref.isShared()
+ if (d.needsDetach()
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
d->detachCapacity(size() + (last - first)),
@@ -232,7 +232,7 @@ public:
if (first == last)
return;
- if (d->ref.isShared()
+ if (d.needsDetach()
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
d->detachCapacity(size() + (last - first)),
@@ -272,7 +272,7 @@ public:
T *const begin = d->begin();
T *const where = begin + position;
const T *const end = begin + d->size;
- if (d->ref.isShared()
+ if (d.needsDetach()
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
d->detachCapacity(size() + (last - first)),