diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-02-16 09:04:11 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-02-21 19:56:07 +0100 |
commit | 147dd6e82f41778060bdadf9b2a792bd11e1bc1e (patch) | |
tree | 97540dc1fd6efb14d613a72f70f48377f79c0349 | |
parent | bb2ff8a69f8bec057c944610f8c4c97009e27ed1 (diff) |
QVarLengthArray: Extract Method QtPrivate::q_rotate()
It seems like we'll need this in lots of other places, too.
Pick-to: 6.5 6.4 6.2 5.15
Change-Id: I767495c2eb02a2fc85b6f835ad9003fa89315c7f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/tools/qcontainertools_impl.h | 20 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 7 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index f63a583d4c..dec60aa076 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -88,6 +88,26 @@ QT_WARNING_POP /*! \internal + + A wrapper around std::rotate(), with an optimization for + Q_RELOCATABLE_TYPEs. We omit the return value, as it would be more work to + compute in the Q_RELOCATABLE_TYPE case and, unlike std::rotate on + ForwardIterators, callers can compute the result in constant time + themselves. +*/ +template <typename T> +void q_rotate(T *first, T *mid, T *last) +{ + if constexpr (QTypeInfo<T>::isRelocatable) { + const auto cast = [](T *p) { return reinterpret_cast<uchar*>(p); }; + std::rotate(cast(first), cast(mid), cast(last)); + } else { + std::rotate(first, mid, last); + } +} + +/*! + \internal Copies all elements, except the ones for which \a pred returns \c true, from range [first, last), to the uninitialized memory buffer starting at \a out. diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index dc6e88e3e8..6bd2ecdf4c 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -916,12 +916,7 @@ Q_OUTOFLINE_TEMPLATE auto QVLABase<T>::emplace_impl(qsizetype prealloc, void *ar emplace_back_impl(prealloc, array, std::forward<Args>(args)...); const auto b = begin() + offset; const auto e = end(); - if constexpr (QTypeInfo<T>::isRelocatable) { - auto cast = [](T *p) { return reinterpret_cast<uchar*>(p); }; - std::rotate(cast(b), cast(e - 1), cast(e)); - } else { - std::rotate(b, e - 1, e); - } + QtPrivate::q_rotate(b, e - 1, e); return b; } |