diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-10-13 09:43:45 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-10-13 19:34:36 +0200 |
commit | 9422dd0e19bcd2b54ae3eecc9917ddc83368c0f2 (patch) | |
tree | ec8129fcd6252c18389cfbff82813a9b250a65b6 | |
parent | 507be11303c8dd9709d903f8e5ec197be66209ce (diff) |
QList: remove yet another iterator->pointer implicit conversion
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 <fabian.kosmale@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/tools/qlist.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c1d59617c3..6f0e0931d4 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>; T *i = nullptr; public: using difference_type = qsizetype; @@ -178,6 +179,7 @@ public: }; class const_iterator { + friend class QList<T>; 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<std::decay_t<InputIterator>, iterator> || std::is_same_v<std::decay_t<InputIterator>, const_iterator>) { - d->copyAppend(i1, i2); + d->copyAppend(i1.i, i2.i); } else { d->appendIteratorRange(i1, i2); } |