From 4af6ba40c29af98f4ecb01d9d2654c02043c3e44 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 30 Nov 2021 16:35:06 +0100 Subject: [PATCH] QVLA: separate control from inline storage [6/N]: emplace_back() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move emplace_back() down from QVarLengthArray to QVLABase. Task-number: QTBUG-84785 Change-Id: I29020737007f245c3b52fd7960369262510c0d52 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 4c8fbc3e0e..d8eab35a56 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -194,6 +194,16 @@ public: iterator erase(const_iterator pos) { return erase(pos, pos + 1); } protected: + template + reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args) + { + if (size() == capacity()) // ie. size() != 0 + reallocate_impl(prealloc, array, size(), size() << 1); + reference r = *new (end()) T(std::forward(args)...); + ++s; + return r; + } + template bool equal(const QVLABase &other) const { @@ -514,7 +524,8 @@ public: template iterator emplace(const_iterator pos, Args &&...args); template - T &emplace_back(Args &&...args) { return *emplace(cend(), std::forward(args)...); } + T &emplace_back(Args &&...args) + { return Base::emplace_back_impl(Prealloc, this->array, std::forward(args)...); } #ifdef Q_QDOC