From 2e51686746c45055e5bb74f58e0c159bfb6a8c13 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 24 Jun 2020 20:34:15 +0200 Subject: [PATCH] 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 --- src/corelib/tools/qlist.h | 8 ++++---- 1 file 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 = 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 = true> QList(InputIterator i1, InputIterator i2) - : QList() { - QtPrivate::reserveIfForwardIterator(this, i1, i2); std::copy(i1, i2, std::back_inserter(*this)); }