diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-11-06 15:57:03 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-17 11:45:52 +0100 |
commit | fc172c43132a15e17bd435db90e85722c7100361 (patch) | |
tree | b3a48eea73904e9262ef9ba1cee0e0c1300a8a63 /src/corelib/tools/qlist.h | |
parent | ee122077b09430da54ca09750589b37326a22d85 (diff) |
Simplify the code for QList::emplace()
Unify it with the code in QArrayDataOps and only have one
emplace method there that handles it all.
Adjust autotests to API changes in QArrayDataOps and fix a
wrong test case (that just happened to pass by chance before).
Change-Id: Ia08cadebe2f74b82c31f856b1ff8a3d8dc400a3c
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index a5cb560dc0..9c95d49bae 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -743,25 +743,7 @@ typename QList<T>::iterator QList<T>::emplace(qsizetype i, Args&&... args) { Q_ASSERT_X(i >= 0 && i <= d->size, "QList<T>::insert", "index out of range"); - - if (d->needsDetach() || (d.size == d.constAllocatedCapacity())) { - typename QArrayData::GrowthPosition pos = QArrayData::GrowsAtEnd; - if (d.size != 0 && i <= (d.size >> 1)) - pos = QArrayData::GrowsAtBeginning; - - DataPointer detached(DataPointer::allocateGrow(d, 1, pos)); - const_iterator where = constBegin() + i; - - // protect against args being an element of the container - T tmp(std::forward<Args>(args)...); - - detached->copyAppend(constBegin(), where); - detached->emplace(detached.end(), std::move(tmp)); - detached->copyAppend(where, constEnd()); - d.swap(detached); - } else { - d->emplace(d.begin() + i, std::forward<Args>(args)...); - } + d->emplace(i, std::forward<Args>(args)...); return d.begin() + i; } |