diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-06-11 11:18:29 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-10-18 08:25:16 -0700 |
| commit | 3b0af6cc2ffe67ae228f17b2c29daa0d501c5876 (patch) | |
| tree | 87ebad2b118eb0193eb3217aa328e496e5af5906 /src/corelib/tools/qarraydatapointer.h | |
| parent | b3a6d0e28487baa1678bca2098b1e1108f9be6e0 (diff) | |
QArrayDataOps: move assign() from QArrayDataPointer
The implementation was already using the Ops (like in (*this)->emplace),
so this is only natural. We want to access the extra operations anyway.
Change-Id: Id1f422be54154f2c41b0fffd416dcb1916e8f022
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
| -rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index 7fa6f2e7dd9..52984e40f31 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -7,9 +7,6 @@ #include <QtCore/qarraydataops.h> #include <QtCore/qcontainertools_impl.h> -#include <QtCore/q20functional.h> -#include <QtCore/q20memory.h> - QT_BEGIN_NAMESPACE template <class T> @@ -320,98 +317,6 @@ public: this->ptr = res; } - template <typename InputIterator, typename Projection = q20::identity> - void assign(InputIterator first, InputIterator last, Projection proj = {}) - { - // This function only provides the basic exception guarantee. - constexpr bool IsFwdIt = std::is_convertible_v< - typename std::iterator_traits<InputIterator>::iterator_category, - std::forward_iterator_tag>; - constexpr bool IsIdentity = std::is_same_v<Projection, q20::identity>; - - if constexpr (IsFwdIt) { - const qsizetype n = std::distance(first, last); - if (needsDetach() || n > constAllocatedCapacity()) { - QArrayDataPointer allocated(detachCapacity(n)); - swap(allocated); - } - } else if (needsDetach()) { - QArrayDataPointer allocated(allocatedCapacity()); - swap(allocated); - // We don't want to copy data that we know we'll overwrite - } - - auto offset = freeSpaceAtBegin(); - const auto capacityBegin = begin() - offset; - const auto prependBufferEnd = begin(); - - if constexpr (!std::is_nothrow_constructible_v<T, decltype(std::invoke(proj, *first))>) { - // If construction can throw, and we have freeSpaceAtBegin(), - // it's easiest to just clear the container and start fresh. - // The alternative would be to keep track of two active, disjoint ranges. - if (offset) { - (*this)->truncate(0); - setBegin(capacityBegin); - offset = 0; - } - } - - auto dst = capacityBegin; - const auto dend = end(); - if (offset) { // avoids dead stores - setBegin(capacityBegin); // undo prepend optimization - - // By construction, the following loop is nothrow! - // (otherwise, we can't reach here) - // Assumes InputIterator operations don't throw. - // (but we can't statically assert that, as these operations - // have preconditons, so typically aren't noexcept) - while (true) { - if (dst == prependBufferEnd) { // ran out of prepend buffer space - size += offset; - // we now have a contiguous buffer, continue with the main loop: - break; - } - if (first == last) { // ran out of elements to assign - std::destroy(prependBufferEnd, dend); - size = dst - begin(); - return; - } - // construct element in prepend buffer - q20::construct_at(dst, std::invoke(proj, *first)); - ++dst; - ++first; - } - } - - while (true) { - if (first == last) { // ran out of elements to assign - std::destroy(dst, dend); - break; - } - if (dst == dend) { // ran out of existing elements to overwrite - if constexpr (IsFwdIt && IsIdentity) { - dst = std::uninitialized_copy(first, last, dst); - break; - } else if constexpr (IsFwdIt && !IsIdentity - && std::is_nothrow_constructible_v<T, decltype(std::invoke(proj, *first))>) { - for (; first != last; ++dst, ++first) // uninitialized_copy with projection - q20::construct_at(dst, std::invoke(proj, *first)); - break; - } else { - do { - (*this)->emplace(size, std::invoke(proj, *first)); - } while (++first != last); - return; // size() is already correct (and dst invalidated)! - } - } - *dst = std::invoke(proj, *first); // overwrite existing element - ++dst; - ++first; - } - size = dst - begin(); - } - QArrayDataPointer sliced(qsizetype pos, qsizetype n) const & { QArrayDataPointer result(n); |
