summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydatapointer.h
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-11-22 17:28:14 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 17:19:30 +0100
commitf1e48d48fd58b28b1dc18652af3fc74da5e112fd (patch)
tree41f355093999ea8dabf9c196afb4e0ad275ce547 /src/corelib/tools/qarraydatapointer.h
parentd91b4f0b13926a0861d7e172f14437d20d06332e (diff)
Add AllocateOptions to QArrayData
This approach is better for future ABI evolution than using individual bool parameters. QArrayData now also offers to calculate allocate options for typical detach and clone operations: the CapacityReserved flag is preserved, while cloning resets the Unsharable state. Change-Id: I256e135adcf27a52a5c7d6130069c35c8b946bc3 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r--src/corelib/tools/qarraydatapointer.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index c03e2ef849..1dc02daa63 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -66,7 +66,7 @@ public:
QArrayDataPointer(const QArrayDataPointer &other)
: d(other.d->ref.ref()
? other.d
- : other.clone())
+ : other.clone(other.d->cloneFlags()))
{
}
@@ -115,7 +115,9 @@ public:
void setSharable(bool sharable)
{
if (d->alloc == 0 && d->size == 0) {
- d = Data::allocate(0, false, sharable);
+ d = Data::allocate(0, sharable
+ ? QArrayData::Default
+ : QArrayData::Unsharable);
return;
}
@@ -137,7 +139,7 @@ public:
bool detach()
{
if (d->ref.isShared()) {
- Data *copy = clone();
+ Data *copy = clone(d->detachFlags());
QArrayDataPointer old(d);
d = copy;
return true;
@@ -147,10 +149,10 @@ public:
}
private:
- Data *clone() const Q_REQUIRED_RESULT
+ Data *clone(QArrayData::AllocateOptions options) const Q_REQUIRED_RESULT
{
QArrayDataPointer copy(Data::allocate(d->alloc ? d->alloc : d->size,
- d->capacityReserved));
+ options));
if (d->size)
copy->copyAppend(d->begin(), d->end());