QVarLengthArray: make static if's constexpr

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 <lars.knoll@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2021-11-26 14:58:12 +01:00
parent bda75c81f5
commit f814241abe

View File

@ -407,7 +407,7 @@ Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype asize)
ptr = reinterpret_cast<T *>(array);
a = Prealloc;
}
if (QTypeInfo<T>::isComplex) {
if constexpr (QTypeInfo<T>::isComplex) {
T *i = end();
while (i != begin())
new (--i) T;
@ -516,7 +516,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::reallocate(qsizetype asi
a = Prealloc;
}
s = 0;
if (!QTypeInfo<T>::isRelocatable) {
if constexpr (!QTypeInfo<T>::isRelocatable) {
QT_TRY {
// move all the old elements
while (size() < copySize) {
@ -548,7 +548,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::reallocate(qsizetype asi
if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != data())
free(oldPtr);
if (QTypeInfo<T>::isComplex) {
if constexpr (QTypeInfo<T>::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<T, Prealloc>::emplace(const_iterator b
qsizetype offset = qsizetype(before - begin());
if (size() == capacity())
reserve(size() * 2);
if (!QTypeInfo<T>::isRelocatable) {
if constexpr (!QTypeInfo<T>::isRelocatable) {
T *b = begin() + offset;
T *i = end();
T *j = i + 1;
@ -661,7 +661,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
if (n != 0) {
const T copy(t); // `t` could alias an element in [begin(), end()[
resize(size() + n);
if (!QTypeInfo<T>::isRelocatable) {
if constexpr (!QTypeInfo<T>::isRelocatable) {
T *b = begin() + offset;
T *j = end();
T *i = j - n;