summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata/simplevector.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata/simplevector.h')
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 36c9b7bc50..4aa3ab09c8 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -135,6 +135,113 @@ public:
return *(end() - 1);
}
+ void reserve(size_t n)
+ {
+ if (n > capacity()
+ || (n
+ && !d->capacityReserved
+ && (d->ref != 1 || (d->capacityReserved = 1, false)))) {
+ SimpleVector detached(Data::allocate(n, true));
+ static_cast<DataOps *>(detached.d)->copyAppend(constBegin(), constEnd());
+ detached.swap(*this);
+ }
+ }
+
+ void prepend(const_iterator first, const_iterator last)
+ {
+ if (!d->size) {
+ append(first, last);
+ return;
+ }
+
+ if (first == last)
+ return;
+
+ T *const begin = d->begin();
+ if (d->ref != 1
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)), d->capacityReserved));
+
+ static_cast<DataOps *>(detached.d)->copyAppend(first, last);
+ static_cast<DataOps *>(detached.d)->copyAppend(begin, begin + d->size);
+ detached.swap(*this);
+
+ return;
+ }
+
+ static_cast<DataOps *>(d)->insert(begin, first, last);
+ }
+
+ void append(const_iterator first, const_iterator last)
+ {
+ if (first == last)
+ return;
+
+ if (d->ref != 1
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)), d->capacityReserved));
+
+ if (d->size) {
+ const T *const begin = constBegin();
+ static_cast<DataOps *>(detached.d)->copyAppend(begin, begin + d->size);
+ }
+ static_cast<DataOps *>(detached.d)->copyAppend(first, last);
+ detached.swap(*this);
+
+ return;
+ }
+
+ static_cast<DataOps *>(d)->copyAppend(first, last);
+ }
+
+ void insert(int position, const_iterator first, const_iterator last)
+ {
+ if (position < 0)
+ position += d->size + 1;
+
+ if (position <= 0) {
+ prepend(first, last);
+ return;
+ }
+
+ if (size_t(position) >= size()) {
+ append(first, last);
+ return;
+ }
+
+ if (first == last)
+ return;
+
+ T *const begin = d->begin();
+ T *const where = begin + position;
+ const T *const end = begin + d->size;
+ if (d->ref != 1
+ || capacity() - size() < size_t(last - first)) {
+ SimpleVector detached(Data::allocate(
+ qMax(capacity(), size() + (last - first)), d->capacityReserved));
+
+ if (position)
+ static_cast<DataOps *>(detached.d)->copyAppend(begin, where);
+ static_cast<DataOps *>(detached.d)->copyAppend(first, last);
+ static_cast<DataOps *>(detached.d)->copyAppend(where, end);
+ detached.swap(*this);
+
+ return;
+ }
+
+ // Temporarily copy overlapping data, if needed
+ if ((first >= where && first < end)
+ || (last > where && last <= end)) {
+ SimpleVector tmp(first, last);
+ static_cast<DataOps *>(d)->insert(where, tmp.constBegin(), tmp.constEnd());
+ return;
+ }
+
+ static_cast<DataOps *>(d)->insert(where, first, last);
+ }
+
void swap(SimpleVector &other)
{
qSwap(d, other.d);