From 54ed4e6b6aa133724ee9006bcef5bf53fe2d46bd Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 24 Nov 2020 16:08:30 +0100 Subject: [PATCH] QVLA: always use new to create new objects Even for non-complex types, it makes no sense to use the assignment operator instead of placement new when constructing new objects. Change-Id: I5f15fe4b3397cf52d1d35e6c4dcc513b94b3cf14 Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira Reviewed-by: Andrei Golubev (cherry picked from commit e6e67f31c10da900ec6ecb06c2e827b17283be6a) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qvarlengtharray.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 975d088a480..6a99602153a 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -220,18 +220,10 @@ public: T copy(t); reallocate(s, s << 1); const qsizetype idx = s++; - if (QTypeInfo::isComplex) { - new (ptr + idx) T(std::move(copy)); - } else { - ptr[idx] = std::move(copy); - } + new (ptr + idx) T(std::move(copy)); } else { const qsizetype idx = s++; - if (QTypeInfo::isComplex) { - new (ptr + idx) T(t); - } else { - ptr[idx] = t; - } + new (ptr + idx) T(t); } } @@ -240,10 +232,7 @@ public: if (s == a) reallocate(s, s << 1); const qsizetype idx = s++; - if (QTypeInfo::isComplex) - new (ptr + idx) T(std::move(t)); - else - ptr[idx] = std::move(t); + new (ptr + idx) T(std::move(t)); } void append(const T *buf, qsizetype size);