summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-24 20:34:15 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-07-06 17:59:07 +0200
commit2e51686746c45055e5bb74f58e0c159bfb6a8c13 (patch)
tree2bc4e2c2c90d1ee3f7682c3b1925176af2ec8fcd /src/corelib
parent95326a2977ddb734716c0d17e3edcdb00c5c4bca (diff)
QList: improve the range constructors
In case of forward iterators, call std::distance just once and not twice. In case of non-forward iterators, don't call reserveIfForwardIterator -- as the name says, it doesn't make sense on non-forward iterators. Change-Id: I7e6a603205286c05f7bc7c47fd1f1e0d92705b20 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qlist.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e041b4132a..5d0a95fb0b 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -144,17 +144,17 @@ public:
}
template <typename InputIterator, QtPrivate::IfIsForwardIterator<InputIterator> = true>
QList(InputIterator i1, InputIterator i2)
- : d(Data::allocate(std::distance(i1, i2)))
{
- if (std::distance(i1, i2))
+ const auto distance = std::distance(i1, i2);
+ if (distance) {
+ d = DataPointer(Data::allocate(distance));
d->copyAppend(i1, i2);
+ }
}
template <typename InputIterator, QtPrivate::IfIsNotForwardIterator<InputIterator> = true>
QList(InputIterator i1, InputIterator i2)
- : QList()
{
- QtPrivate::reserveIfForwardIterator(this, i1, i2);
std::copy(i1, i2, std::back_inserter(*this));
}