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>
This commit is contained in:
parent
507be11303
commit
9422dd0e19
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user