diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-08 13:31:42 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-12-11 16:56:56 +0100 |
commit | d3d284bec423d936e936cdb756b6e1bd2ad537b8 (patch) | |
tree | 9ad3cc0ff7da31e172e254c262ead2292ee20c4b /src/corelib | |
parent | 69f05a384f44db961268ea5df0511973417cdc45 (diff) | |
download | qtbase-d3d284bec423d936e936cdb756b6e1bd2ad537b8.tar.gz |
QVLA: separate control from inline storage [10/N]: range-insert()
Also added a QVLABase::resize_impl() because insert(it, n, v) was the
only function moved down into QVLABase to call resize().
Task-number: QTBUG-84785
Change-Id: I5dd0092216d73b28b957a01845325d744a5c0ba9
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index e51361623b..e6ff615b03 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -206,6 +206,8 @@ protected: template <typename...Args> iterator emplace_impl(qsizetype prealloc, void *array, const_iterator pos, Args&&...arg); + iterator insert_impl(qsizetype prealloc, void *array, const_iterator pos, qsizetype n, const T &t); + template <typename S> bool equal(const QVLABase<S> &other) const { @@ -219,6 +221,8 @@ protected: void append_impl(qsizetype prealloc, void *array, const T *buf, qsizetype n); void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc); + void resize_impl(qsizetype prealloc, void *array, qsizetype sz) + { reallocate_impl(prealloc, array, sz, qMax(sz, capacity())); } bool isValidIterator(const const_iterator &i) const { @@ -371,7 +375,7 @@ public: return back(); } bool isEmpty() const { return empty(); } - void resize(qsizetype sz) { reallocate(sz, qMax(sz, capacity())); } + void resize(qsizetype sz) { Base::resize_impl(Prealloc, this->array, sz); } inline void clear() { resize(0); } void squeeze() { reallocate(size(), size()); } @@ -498,7 +502,8 @@ public: using Base::rend; using Base::crend; - iterator insert(const_iterator before, qsizetype n, const T &x); + iterator insert(const_iterator before, qsizetype n, const T &x) + { return Base::insert_impl(Prealloc, this->array, before, n, x); } iterator insert(const_iterator before, T &&x) { return emplace(before, std::move(x)); } inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); } #ifdef Q_QDOC @@ -845,15 +850,15 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *ar return data() + offset; } -template <class T, qsizetype Prealloc> -Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthArray<T, Prealloc>::insert(const_iterator before, qsizetype n, const T &t) +template <class T> +Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::insert_impl(qsizetype prealloc, void *array, const_iterator before, qsizetype n, const T &t) -> iterator { Q_ASSERT_X(isValidIterator(before), "QVarLengthArray::insert", "The specified const_iterator argument 'before' is invalid"); qsizetype offset = qsizetype(before - cbegin()); if (n != 0) { const T copy(t); // `t` could alias an element in [begin(), end()[ - resize(size() + n); + resize_impl(prealloc, array, size() + n); if constexpr (!QTypeInfo<T>::isRelocatable) { T *b = begin() + offset; T *j = end(); |