diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-01-09 09:36:04 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-01-12 19:54:13 +0100 |
commit | 26b227e128475da3f88a6b34921a08994bf71cf4 (patch) | |
tree | 22233f7ba8aaac7ba4e41ccc690a1f5706d9a004 /src | |
parent | 7c5ff43ea322422f03f6b87768d825f2df6f1652 (diff) |
QVarLengthArray: Extract Method growBy()
Separates the actual reallocation use-cases from the resizing ones
when calling reallocate_impl, in preparation for fixing QTBUG-109745.
Task-number: QTBUG-109745
Pick-to: 6.5 6.4
Change-Id: Iee0c3e56569ec7877beda8db3a645e2bbb6b4d4a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 469fbda2aa..204364b52f 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -180,11 +180,13 @@ public: return qHashRange(begin(), end(), seed); } protected: + void growBy(qsizetype prealloc, void *array, qsizetype increment) + { reallocate_impl(prealloc, array, size(), (std::max)(size() * 2, increment)); } template <typename...Args> reference emplace_back_impl(qsizetype prealloc, void *array, Args&&...args) { if (size() == capacity()) // ie. size() != 0 - reallocate_impl(prealloc, array, size(), size() << 1); + growBy(prealloc, array, 1); reference r = *new (end()) T(std::forward<Args>(args)...); ++s; return r; @@ -701,7 +703,7 @@ Q_OUTOFLINE_TEMPLATE void QVLABase<T>::append_impl(qsizetype prealloc, void *arr const qsizetype asize = size() + increment; if (asize >= capacity()) - reallocate_impl(prealloc, array, size(), qMax(size() * 2, asize)); + growBy(prealloc, array, increment); if constexpr (QTypeInfo<T>::isComplex) std::uninitialized_copy_n(abuf, increment, end()); @@ -842,7 +844,7 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *ar qsizetype offset = qsizetype(before - cbegin()); if (size() == capacity()) - reallocate_impl(prealloc, array, size(), size() * 2); + growBy(prealloc, array, 1); if constexpr (!QTypeInfo<T>::isRelocatable) { T *b = begin() + offset; T *i = end(); |