From 99894e33ba692946744ebef1ed0c246ec7bd483f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 8 Dec 2021 13:31:42 +0100 Subject: [PATCH] QVLA: separate control from inline storage [8/N]: emplace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moving emplace() takes care of the bulk of insert()-like operations in QVarLengthArray. What's missing now is just the pseudo-ranged insert(i, n, x) and append(ptr, n) operations. Task-number: QTBUG-84785 Change-Id: I8be7f50ecab3de79b617436c46d3feec065b4f88 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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();