From f814241abec7cb5317e2c7bf1f9722b2c671a9ba Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Nov 2021 14:58:12 +0100 Subject: QVarLengthArray: make static if's constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleaner. Probably also more efficient at compile time, who knows? Also more consistent, since _some_ static if's were already constexpr'ed. Change-Id: I9657f7cf2166975f562db52e9f90630aaf412986 Reviewed-by: Lars Knoll Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 47062fc788..7882efb4c8 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -407,7 +407,7 @@ Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(qsizetype asize) ptr = reinterpret_cast(array); a = Prealloc; } - if (QTypeInfo::isComplex) { + if constexpr (QTypeInfo::isComplex) { T *i = end(); while (i != begin()) new (--i) T; @@ -516,7 +516,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocate(qsizetype asi a = Prealloc; } s = 0; - if (!QTypeInfo::isRelocatable) { + if constexpr (!QTypeInfo::isRelocatable) { QT_TRY { // move all the old elements while (size() < copySize) { @@ -548,7 +548,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocate(qsizetype asi if (oldPtr != reinterpret_cast(array) && oldPtr != data()) free(oldPtr); - if (QTypeInfo::isComplex) { + if constexpr (QTypeInfo::isComplex) { // call default constructor for new objects (which can throw) while (size() < asize) { new (data() + size()) T; @@ -630,7 +630,7 @@ Q_OUTOFLINE_TEMPLATE auto QVarLengthArray::emplace(const_iterator b qsizetype offset = qsizetype(before - begin()); if (size() == capacity()) reserve(size() * 2); - if (!QTypeInfo::isRelocatable) { + if constexpr (!QTypeInfo::isRelocatable) { T *b = begin() + offset; T *i = end(); T *j = i + 1; @@ -661,7 +661,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthA if (n != 0) { const T copy(t); // `t` could alias an element in [begin(), end()[ resize(size() + n); - if (!QTypeInfo::isRelocatable) { + if constexpr (!QTypeInfo::isRelocatable) { T *b = begin() + offset; T *j = end(); T *i = j - n; -- cgit v1.2.3