From 69f05a384f44db961268ea5df0511973417cdc45 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 [9/N]: range-append() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-84785 Change-Id: Ieca9b3b8608b9500393d2d9d1910380799aba2ea Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Qt CI Bot --- src/corelib/tools/qvarlengtharray.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a03aa3cc4c..e51361623b 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -217,6 +217,7 @@ protected: return std::lexicographical_compare(begin(), end(), other.begin(), other.end()); } + void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n); void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc); bool isValidIterator(const const_iterator &i) const @@ -426,7 +427,8 @@ public: emplace_back(std::move(t)); } - void append(const T *buf, qsizetype size); + void append(const T *buf, qsizetype sz) + { Base::append_impl(Prealloc, this->array, buf, sz); } inline QVarLengthArray &operator<<(const T &t) { append(t); return *this; } inline QVarLengthArray &operator<<(T &&t) @@ -675,8 +677,8 @@ Q_INLINE_TEMPLATE bool QVLABase::contains(const AT &t) const return false; } -template -Q_OUTOFLINE_TEMPLATE void QVarLengthArray::append(const T *abuf, qsizetype increment) +template +Q_OUTOFLINE_TEMPLATE void QVLABase::append_impl(qsizetype prealloc, void *array, const T *abuf, qsizetype increment) { Q_ASSERT(abuf || increment == 0); if (increment <= 0) @@ -685,7 +687,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::append(const T *abuf, qs const qsizetype asize = size() + increment; if (asize >= capacity()) - reallocate(size(), qMax(size() * 2, asize)); + reallocate_impl(prealloc, array, size(), qMax(size() * 2, asize)); if constexpr (QTypeInfo::isComplex) std::uninitialized_copy_n(abuf, increment, end());