From f1e48d48fd58b28b1dc18652af3fc74da5e112fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 22 Nov 2011 17:28:14 +0100 Subject: Add AllocateOptions to QArrayData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/tools/qarraydatapointer.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/corelib/tools/qarraydatapointer.h') 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()); -- cgit v1.2.3