From: João Abecasis Date: Fri, 25 Nov 2011 13:12:54 +0000 (+0100) Subject: Add setSharable support to SimpleVector X-Git-Tag: 071012110112~1235^2^2~294^2^2~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25b8b2437ca4dc2d77ab985f491867bdbe2fff32;p=profile%2Fivi%2Fqtbase.git Add setSharable support to SimpleVector Change-Id: I606064d86b58be1a6a57f64f4eb55a4a751a0811 Reviewed-by: Thiago Macieira --- diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h index 4f02df1..e7032f0 100644 --- a/tests/auto/corelib/tools/qarraydata/simplevector.h +++ b/tests/auto/corelib/tools/qarraydata/simplevector.h @@ -89,6 +89,9 @@ public: bool isStatic() const { return d->ref.isStatic(); } bool isShared() const { return d->ref.isShared(); } bool isSharedWith(const SimpleVector &other) const { return d == other.d; } + bool isSharable() const { return d->ref.isSharable(); } + + void setSharable(bool sharable) { d.setSharable(sharable); } size_t size() const { return d->size; } size_t capacity() const { return d->alloc; } @@ -139,7 +142,7 @@ public: if (n > capacity() || (n && !d->capacityReserved - && (d->ref != 1 || (d->capacityReserved = 1, false)))) { + && (d->ref.isShared() || (d->capacityReserved = 1, false)))) { SimpleVector detached(Data::allocate(n, d->detachFlags() | Data::CapacityReserved)); detached.d->copyAppend(constBegin(), constEnd()); @@ -158,7 +161,7 @@ public: return; T *const begin = d->begin(); - if (d->ref != 1 + if (d->ref.isShared() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( qMax(capacity(), size() + (last - first)), @@ -179,7 +182,7 @@ public: if (first == last) return; - if (d->ref != 1 + if (d->ref.isShared() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( qMax(capacity(), size() + (last - first)), @@ -219,7 +222,7 @@ public: T *const begin = d->begin(); T *const where = begin + position; const T *const end = begin + d->size; - if (d->ref != 1 + if (d->ref.isShared() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( qMax(capacity(), size() + (last - first)), diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 2df4131..90c865c 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -292,6 +292,15 @@ void tst_QArrayData::simpleVector() QVERIFY(!v7.isShared()); QVERIFY(!v8.isShared()); + QVERIFY(v1.isSharable()); + QVERIFY(v2.isSharable()); + QVERIFY(v3.isSharable()); + QVERIFY(v4.isSharable()); + QVERIFY(v5.isSharable()); + QVERIFY(v6.isSharable()); + QVERIFY(v7.isSharable()); + QVERIFY(v8.isSharable()); + QVERIFY(v1.isSharedWith(v2)); QVERIFY(v1.isSharedWith(v3)); QVERIFY(!v1.isSharedWith(v4)); @@ -451,6 +460,69 @@ void tst_QArrayData::simpleVector() for (int i = 0; i < 120; ++i) QCOMPARE(v1[i], v8[i % 10]); + + { + v7.setSharable(true); + QVERIFY(v7.isSharable()); + + SimpleVector copy1(v7); + QVERIFY(copy1.isSharedWith(v7)); + + v7.setSharable(false); + QVERIFY(!v7.isSharable()); + + QVERIFY(!copy1.isSharedWith(v7)); + QCOMPARE(v7.size(), copy1.size()); + for (size_t i = 0; i < copy1.size(); ++i) + QCOMPARE(v7[i], copy1[i]); + + SimpleVector clone(v7); + QVERIFY(!clone.isSharedWith(v7)); + QCOMPARE(clone.size(), copy1.size()); + for (size_t i = 0; i < copy1.size(); ++i) + QCOMPARE(clone[i], copy1[i]); + + v7.setSharable(true); + QVERIFY(v7.isSharable()); + + SimpleVector copy2(v7); + QVERIFY(copy2.isSharedWith(v7)); + } + + { + SimpleVector null; + SimpleVector empty(0, 5); + + QVERIFY(null.isSharable()); + QVERIFY(empty.isSharable()); + + null.setSharable(true); + empty.setSharable(true); + + QVERIFY(null.isSharable()); + QVERIFY(empty.isSharable()); + + QVERIFY(null.isEmpty()); + QVERIFY(empty.isEmpty()); + + null.setSharable(false); + empty.setSharable(false); + + QVERIFY(!null.isSharable()); + QVERIFY(!empty.isSharable()); + + QVERIFY(null.isEmpty()); + QVERIFY(empty.isEmpty()); + + null.setSharable(true); + empty.setSharable(true); + + QVERIFY(null.isSharable()); + QVERIFY(empty.isSharable()); + + QVERIFY(null.isEmpty()); + QVERIFY(empty.isEmpty()); + } } struct Deallocator