diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 6b775fd47c..1efa94ebd1 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -932,41 +932,6 @@ public: ++this->size; } } - -public: - - template - void emplaceBack(Args&&... args) - { - if (this->needsDetach() || !this->freeSpaceAtEnd()) { - // protect against args being an element of the container - T tmp(std::forward(args)...); - this->reallocateAndGrow(QArrayData::GrowsAtEnd, 1); - Q_ASSERT(!this->isShared()); - Q_ASSERT(this->freeSpaceAtEnd() >= 1); - new (this->end()) T(std::move(tmp)); - } else { - new (this->end()) T(std::forward(args)...); - } - ++this->size; - } - - template - void emplaceFront(Args&&... args) - { - if (this->needsDetach() || !this->freeSpaceAtBegin()) { - // protect against args being an element of the container - T tmp(std::forward(args)...); - this->reallocateAndGrow(QArrayData::GrowsAtBeginning, 1); - Q_ASSERT(!this->isShared()); - Q_ASSERT(this->freeSpaceAtBegin() >= 1); - new (this->ptr - 1) T(std::move(tmp)); - } else { - new (this->ptr - 1) T(std::forward(args)...); - } - --this->ptr; - ++this->size; - } }; } // namespace QtPrivate diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index a2cbfb0f36..daf9d43fd9 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -715,7 +715,7 @@ template template inline typename QList::reference QList::emplaceFront(Args &&... args) { - d->emplaceFront(std::forward(args)...); + d->emplace(0, std::forward(args)...); return *d.begin(); } @@ -744,7 +744,7 @@ template template inline typename QList::reference QList::emplaceBack(Args &&... args) { - d->emplaceBack(std::forward(args)...); + d->emplace(d->size, std::forward(args)...); return *(d.end() - 1); } diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 3bad143af5..94ed26710f 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -2205,7 +2205,7 @@ void tst_QArrayData::selfEmplaceBackwards() const auto testSelfEmplace = [&](auto dummy, int spaceAtEnd, auto initValues) { auto adp = createDataPointer(100, spaceAtEnd, dummy); for (auto v : initValues) { - adp->emplaceBack(v); + adp->emplace(adp.size, v); } QVERIFY(!adp.freeSpaceAtEnd()); QVERIFY(adp.freeSpaceAtBegin()); @@ -2244,11 +2244,12 @@ void tst_QArrayData::selfEmplaceForward() }; const auto testSelfEmplace = [&](auto dummy, int spaceAtBegin, auto initValues) { - auto adp = createDataPointer(100, spaceAtBegin, dummy); + // need a -1 below as the first emplace will go towards the end (as the array is still empty) + auto adp = createDataPointer(100, spaceAtBegin - 1, dummy); auto reversedInitValues = initValues; std::reverse(reversedInitValues.begin(), reversedInitValues.end()); for (auto v : reversedInitValues) { - adp->emplaceFront(v); + adp->emplace(0, v); } QVERIFY(!adp.freeSpaceAtBegin()); QVERIFY(adp.freeSpaceAtEnd());