From 590d4b3443ee94425e4513ab20a40823ec5ed4e4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 10 Nov 2020 11:00:26 +0100 Subject: [PATCH] Use std::destroy() instead if handwritten loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia75296abf804332bb6f53dbb9a2eed8600b6e8b4 Reviewed-by: Thiago Macieira Reviewed-by: Andrei Golubev Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qarraydataops.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 0ac34ae5fb7..e2ff3f676b3 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -509,10 +509,8 @@ public: Q_ASSERT(!this->isShared()); Q_ASSERT(newSize < size_t(this->size)); - const T *const b = this->begin(); - do { - (b + --this->size)->~T(); - } while (size_t(this->size) != newSize); + std::destroy(this->begin() + newSize, this->end()); + this->size = newSize; } void destroyAll() // Call from destructors, ONLY @@ -523,11 +521,7 @@ public: Q_ASSERT(this->d->ref_.loadRelaxed() == 0); - const T *const b = this->begin(); - const T *i = this->end(); - - while (i != b) - (--i)->~T(); + std::destroy(this->begin(), this->end()); } void insert(GrowsForwardTag, T *where, const T *b, const T *e)