diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index a0c3da7cce..30a322c892 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -228,9 +228,6 @@ struct QArrayExceptionSafetyPrimitives // Tags for compile-time dispatch based on backwards vs forward growing policy struct GrowsForwardTag {}; struct GrowsBackwardsTag {}; -template struct InverseTag; -template<> struct InverseTag { using tag = GrowsBackwardsTag; }; -template<> struct InverseTag { using tag = GrowsForwardTag; }; QT_WARNING_PUSH #if defined(Q_CC_GNU) && Q_CC_GNU >= 700 @@ -262,7 +259,13 @@ public: } void moveAppend(T *b, T *e) - { insert(this->end(), b, e); } + { + Q_ASSERT(b < e); + Q_ASSERT((e - b) <= this->freeSpaceAtEnd()); + + ::memcpy(static_cast(this->end()), static_cast(b), (e - b) * sizeof(T)); + this->size += (e - b); + } void truncate(size_t newSize) { @@ -282,9 +285,6 @@ public: // exception safe; size not updated. } - void insert(T *where, const T *b, const T *e) - { insert(GrowsForwardTag{}, where, b, e); } - void insert(GrowsForwardTag, T *where, const T *b, const T *e) { Q_ASSERT(this->isMutable() || (b == e && where == this->end())); @@ -320,9 +320,6 @@ public: this->size += (e - b); } - void insert(T *where, size_t n, parameter_type t) - { insert(GrowsForwardTag{}, where, n, t); } - void insert(GrowsForwardTag, T *where, size_t n, parameter_type t) { Q_ASSERT(!this->isShared()); @@ -356,10 +353,6 @@ public: *where++ = t; } - template - void emplace(T *where, Args&&... args) - { emplace(GrowsForwardTag{}, where, std::forward(args)...); } - template void emplace(GrowsForwardTag, T *where, Args&&... args) { @@ -404,9 +397,6 @@ public: ++this->size; } - void erase(T *b, T *e) - { erase(GrowsForwardTag{}, b, e); } - void erase(GrowsForwardTag, T *b, T *e) { Q_ASSERT(this->isMutable()); @@ -555,9 +545,6 @@ public: (--i)->~T(); } - void insert(T *where, const T *b, const T *e) - { insert(GrowsForwardTag{}, where, b, e); } - void insert(GrowsForwardTag, T *where, const T *b, const T *e) { Q_ASSERT(this->isMutable() || (b == e && where == this->end())); @@ -661,9 +648,6 @@ public: } } - void insert(T *where, size_t n, parameter_type t) - { insert(GrowsForwardTag{}, where, n, t); } - void insert(GrowsForwardTag, T *where, size_t n, parameter_type t) { Q_ASSERT(!this->isShared()); @@ -760,10 +744,6 @@ public: } } - template - void emplace(T *where, Args &&... args) - { emplace(GrowsForwardTag{}, where, std::forward(args)...); } - template void emplace(GrowsForwardTag, T *where, Args &&... args) { @@ -836,9 +816,6 @@ public: } } - void erase(T *b, T *e) - { erase(GrowsForwardTag{}, b, e); } - void erase(GrowsForwardTag, T *b, T *e) { Q_ASSERT(this->isMutable()); @@ -947,9 +924,6 @@ public: // using QGenericArrayOps::destroyAll; typedef typename QGenericArrayOps::parameter_type parameter_type; - void insert(T *where, const T *b, const T *e) - { insert(GrowsForwardTag{}, where, b, e); } - void insert(GrowsForwardTag, T *where, const T *b, const T *e) { Q_ASSERT(this->isMutable() || (b == e && where == this->end())); @@ -995,9 +969,6 @@ public: this->size += copiedSize; } - void insert(T *where, size_t n, parameter_type t) - { insert(GrowsForwardTag{}, where, n, t); } - void insert(GrowsForwardTag, T *where, size_t n, parameter_type t) { Q_ASSERT(!this->isShared()); @@ -1042,12 +1013,6 @@ public: // use moving insert using QGenericArrayOps::insert; - template - void emplace(T *where, Args &&... args) - { - emplace(GrowsForwardTag {}, where, std::forward(args)...); - } - template void emplace(GrowsForwardTag, T *where, Args &&... args) { @@ -1090,9 +1055,6 @@ public: // use moving emplace using QGenericArrayOps::emplace; - void erase(T *b, T *e) - { erase(GrowsForwardTag{}, b, e); } - void erase(GrowsForwardTag, T *b, T *e) { Q_ASSERT(this->isMutable()); @@ -1176,46 +1138,6 @@ struct QCommonArrayOps : QArrayOpsSelector::Type protected: using Self = QCommonArrayOps; - // Tag dispatched helper functions - inline void adjustPointer(GrowsBackwardsTag, size_t distance) noexcept - { - this->ptr -= distance; - } - inline void adjustPointer(GrowsForwardTag, size_t distance) noexcept - { - this->ptr += distance; - } - qsizetype freeSpace(GrowsBackwardsTag) const noexcept { return this->freeSpaceAtBegin(); } - qsizetype freeSpace(GrowsForwardTag) const noexcept { return this->freeSpaceAtEnd(); } - - // Tells how much of the given size to insert at the beginning of the - // container. This is insert-specific helper function - qsizetype sizeToInsertAtBegin(const T *const where, qsizetype maxSize) - { - Q_ASSERT(maxSize <= this->allocatedCapacity() - this->size); - Q_ASSERT(where >= this->begin() && where <= this->end()); // in range - - const auto freeAtBegin = this->freeSpaceAtBegin(); - const auto freeAtEnd = this->freeSpaceAtEnd(); - - // Idea: * if enough space on both sides, try to affect less elements - // * if enough space on one of the sides, use only that side - // * otherwise, split between front and back (worst case) - if (freeAtBegin >= maxSize && freeAtEnd >= maxSize) { - if (where - this->begin() < this->end() - where) { - return maxSize; - } else { - return 0; - } - } else if (freeAtBegin >= maxSize) { - return maxSize; - } else if (freeAtEnd >= maxSize) { - return 0; - } else { - return maxSize - freeAtEnd; - } - } - public: // does the iterator point into this array?