diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index c3e9821e81a..6dcdba66195 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -969,15 +969,14 @@ public: Q_ASSERT(newSize > this->size); Q_ASSERT(newSize - this->size <= this->freeSpaceAtEnd()); - T *const b = this->begin(); - do { - auto ptr = b + this->size; - if constexpr (std::is_constructible_v) - new (ptr) T(Qt::Uninitialized); - else - new (ptr) T; // not T() -- default-construct - } while (++this->size != newSize); + T *const b = this->begin() + this->size; + T *const e = this->begin() + newSize; + if constexpr (std::is_constructible_v) + std::uninitialized_fill(b, e, Qt::Uninitialized); + else + std::uninitialized_default_construct(b, e); + this->size = newSize; } };