diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 085c06c550..a03aa3cc4c 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -203,6 +203,8 @@ protected: ++s; return r; } + template + iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg); template bool equal(const QVLABase &other) const @@ -522,7 +524,8 @@ public: using Base::back; void shrink_to_fit() { squeeze(); } template - iterator emplace(const_iterator pos, Args &&...args); + iterator emplace(const_iterator pos, Args &&...args) + { return Base::emplace_impl(Prealloc, this->array, pos, std::forward(args)...); } template T &emplace_back(Args &&...args) { return Base::emplace_back_impl(Prealloc, this->array, std::forward(args)...); } @@ -807,9 +810,9 @@ inline void QVLABase::replace(qsizetype i, const T &t) data()[i] = t; } -template +template template -Q_OUTOFLINE_TEMPLATE auto QVarLengthArray::emplace(const_iterator before, Args &&...args) -> iterator +Q_OUTOFLINE_TEMPLATE auto QVLABase::emplace_impl(qsizetype prealloc, void *array, const_iterator before, Args &&...args) -> iterator { Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid"); Q_ASSERT(size() <= capacity()); @@ -817,7 +820,7 @@ Q_OUTOFLINE_TEMPLATE auto QVarLengthArray::emplace(const_iterator b qsizetype offset = qsizetype(before - cbegin()); if (size() == capacity()) - reserve(size() * 2); + reallocate_impl(prealloc, array, size(), size() * 2); if constexpr (!QTypeInfo::isRelocatable) { T *b = begin() + offset; T *i = end();