diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 1fd7e99c42e..2162512883a 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -356,7 +356,6 @@ public: *where++ = t; } - template void emplace(T *where, Args&&... args) { emplace(GrowsForwardTag{}, where, std::forward(args)...); } @@ -760,13 +759,12 @@ public: } } - - template - void emplace(iterator where, Args&&... args) + template + void emplace(T *where, Args &&... args) { emplace(GrowsForwardTag{}, where, std::forward(args)...); } - template - void emplace(GrowsForwardTag, iterator where, Args&&... args) + template + void emplace(GrowsForwardTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -799,8 +797,8 @@ public: } } - template - void emplace(GrowsBackwardsTag, iterator where, Args&&... args) + template + void emplace(GrowsBackwardsTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1043,14 +1041,14 @@ public: // use moving insert using QGenericArrayOps::insert; - template - void emplace(iterator where, Args &&... args) + template + void emplace(T *where, Args &&... args) { emplace(GrowsForwardTag {}, where, std::forward(args)...); } - template - void emplace(GrowsForwardTag, iterator where, Args &&... args) + template + void emplace(GrowsForwardTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1068,8 +1066,8 @@ public: ++this->size; } - template - void emplace(GrowsBackwardsTag, iterator where, Args &&... args) + template + void emplace(GrowsBackwardsTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1367,18 +1365,19 @@ public: } - - template - void emplace(iterator where, Args&&... args) + template + void emplace(T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(this->allocatedCapacity() - this->size >= 1); + const T *begin = this->begin(); + const T *end = this->end(); // Qt5 QList in insert(1): try to move less data around // Now: - const bool shouldInsertAtBegin = (where - this->begin()) < (this->end() - where) - || this->freeSpaceAtEnd() <= 0; + const bool shouldInsertAtBegin = + (where - begin) < (end - where) || this->freeSpaceAtEnd() <= 0; if (this->freeSpaceAtBegin() > 0 && shouldInsertAtBegin) { Base::emplace(GrowsBackwardsTag{}, where, std::forward(args)...); } else {