Remove the special code for emplaceFront/Back again
emplace() itself now handles those cases fast enough, so there should not be a need to add special code paths for those methods. Change-Id: I3277eb77dd54194e46f96f24de44d7785a6f860a Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
30597cfc0e
commit
c0e1a38f69
@ -932,41 +932,6 @@ public:
|
||||
++this->size;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename ...Args>
|
||||
void emplaceBack(Args&&... args)
|
||||
{
|
||||
if (this->needsDetach() || !this->freeSpaceAtEnd()) {
|
||||
// protect against args being an element of the container
|
||||
T tmp(std::forward<Args>(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>(args)...);
|
||||
}
|
||||
++this->size;
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
void emplaceFront(Args&&... args)
|
||||
{
|
||||
if (this->needsDetach() || !this->freeSpaceAtBegin()) {
|
||||
// protect against args being an element of the container
|
||||
T tmp(std::forward<Args>(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>(args)...);
|
||||
}
|
||||
--this->ptr;
|
||||
++this->size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace QtPrivate
|
||||
|
@ -715,7 +715,7 @@ template<typename T>
|
||||
template<typename... Args>
|
||||
inline typename QList<T>::reference QList<T>::emplaceFront(Args &&... args)
|
||||
{
|
||||
d->emplaceFront(std::forward<Args>(args)...);
|
||||
d->emplace(0, std::forward<Args>(args)...);
|
||||
return *d.begin();
|
||||
}
|
||||
|
||||
@ -744,7 +744,7 @@ template<typename T>
|
||||
template<typename... Args>
|
||||
inline typename QList<T>::reference QList<T>::emplaceBack(Args &&... args)
|
||||
{
|
||||
d->emplaceBack(std::forward<Args>(args)...);
|
||||
d->emplace(d->size, std::forward<Args>(args)...);
|
||||
return *(d.end() - 1);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user