diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index e2ff3f676b3..e0f3484bcb4 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -242,7 +242,7 @@ public: this->size = qsizetype(newSize); } - void moveAppend(T *b, T *e) noexcept + void copyAppend(const T *b, const T *e) noexcept { Q_ASSERT(this->isMutable() || b == e); Q_ASSERT(!this->isShared() || b == e); @@ -256,6 +256,24 @@ public: this->size += (e - b); } + void copyAppend(qsizetype n, parameter_type t) noexcept + { + Q_ASSERT(!this->isShared() || n == 0); + Q_ASSERT(this->freeSpaceAtEnd() >= n); + if (!n) + return; + + T *where = this->end(); + this->size += qsizetype(n); + while (n--) + *where++ = t; + } + + void moveAppend(T *b, T *e) noexcept + { + copyAppend(b, e); + } + void truncate(size_t newSize) noexcept { Q_ASSERT(this->isMutable()); @@ -484,6 +502,38 @@ public: } while (++this->size != newSize); } + void copyAppend(const T *b, const T *e) + { + Q_ASSERT(this->isMutable() || b == e); + Q_ASSERT(!this->isShared() || b == e); + Q_ASSERT(b <= e); + Q_ASSERT((e - b) <= this->freeSpaceAtEnd()); + + if (b == e) // short-cut and handling the case b and e == nullptr + return; + + T *data = this->begin(); + while (b < e) { + new (data + this->size) T(*b); + ++b; + ++this->size; + } + } + + void copyAppend(qsizetype n, parameter_type t) + { + Q_ASSERT(!this->isShared() || n == 0); + Q_ASSERT(this->freeSpaceAtEnd() >= n); + if (!n) + return; + + T *data = this->begin(); + while (n--) { + new (data + this->size) T(t); + ++this->size; + } + } + void moveAppend(T *b, T *e) { Q_ASSERT(this->isMutable() || b == e); @@ -1108,18 +1158,7 @@ public: // using Base::assign; // using Base::compare; - void copyAppend(const T *b, const T *e) - { - Q_ASSERT(this->isMutable() || b == e); - Q_ASSERT(!this->isShared() || b == e); - Q_ASSERT(b <= e); - Q_ASSERT((e - b) <= this->freeSpaceAtEnd()); - - if (b == e) // short-cut and handling the case b and e == nullptr - return; - - Base::insert(GrowsForwardTag{}, this->end(), b, e); - } + using Base::copyAppend; template void copyAppend(It b, It e, QtPrivate::IfIsForwardIterator = true, @@ -1139,16 +1178,6 @@ public: } } - void copyAppend(size_t n, parameter_type t) - { - Q_ASSERT(!this->isShared() || n == 0); - Q_ASSERT(size_t(this->allocatedCapacity() - this->size) >= n); - if (!n) - return; - - Base::insert(GrowsForwardTag{}, this->end(), n, t); - } - public: void insert(qsizetype i, qsizetype n, parameter_type t) {