From 9422dd0e19bcd2b54ae3eecc9917ddc83368c0f2 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 13 Oct 2021 09:43:45 +0200 Subject: [PATCH] QList: remove yet another iterator->pointer implicit conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ranged constructor for QList has an optimization when the iterators are QList's own iterators. In that case, it uses a "contiguous append" shortcut by converting the iterators to pointers. Avoid that conversion by extracting the pointers from the iterators. Note that this is an optimization for C++17 only; in C++20 appendIteratorRange will deal with this case as well. Leave a note. Change-Id: I761c36ff500dee95b4ae1b0a4479d22db0c8e3de Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qlist.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c1d59617c31..6f0e0931d41 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -130,6 +130,7 @@ public: #endif class iterator { + friend class QList; T *i = nullptr; public: using difference_type = qsizetype; @@ -178,6 +179,7 @@ public: }; class const_iterator { + friend class QList; const T *i = nullptr; public: using difference_type = qsizetype; @@ -282,9 +284,11 @@ public: const auto distance = std::distance(i1, i2); if (distance) { d = DataPointer(Data::allocate(distance)); + // appendIteratorRange can deal with contiguous iterators on its own, + // this is an optimization for C++17 code. if constexpr (std::is_same_v, iterator> || std::is_same_v, const_iterator>) { - d->copyAppend(i1, i2); + d->copyAppend(i1.i, i2.i); } else { d->appendIteratorRange(i1, i2); }