From 78e89f39f312aa97ccff6d645c56c89e7bd72571 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 9 Jul 2019 22:27:12 +0000 Subject: [PATCH] QVarLengthArray cleanup Signed-off-by: Ivailo Monev --- src/core/tools/qvarlengtharray.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/core/tools/qvarlengtharray.h b/src/core/tools/qvarlengtharray.h index 8e6b3b0b6..24441e7ea 100644 --- a/src/core/tools/qvarlengtharray.h +++ b/src/core/tools/qvarlengtharray.h @@ -157,23 +157,18 @@ private: int a; // capacity int s; // size T *ptr; // data - union { - // ### Qt 5: Use 'Prealloc * sizeof(T)' as array size - char array[sizeof(qint64) * (((Prealloc * sizeof(T)) / sizeof(qint64)) + 1)]; - qint64 q_for_alignment_1; - double q_for_alignment_2; - }; + T array[Prealloc]; }; template Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(int asize) : s(asize) { if (s > Prealloc) { - ptr = reinterpret_cast(malloc(s * sizeof(T))); + ptr = static_cast(malloc(s * sizeof(T))); Q_CHECK_PTR(ptr); a = s; } else { - ptr = reinterpret_cast(array); + ptr = array; a = Prealloc; } if (QTypeInfo::isComplex) { @@ -222,7 +217,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::realloc(int asize, int a const int copySize = qMin(asize, osize); if (aalloc != a) { - ptr = reinterpret_cast(malloc(aalloc * sizeof(T))); + ptr = static_cast(malloc(aalloc * sizeof(T))); Q_CHECK_PTR(ptr); if (ptr) { s = 0; @@ -241,7 +236,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::realloc(int asize, int a int sClean = s; while (sClean < osize) (oldPtr+(sClean++))->~T(); - if (oldPtr != reinterpret_cast(array) && oldPtr != ptr) + if (oldPtr != array && oldPtr != ptr) free(oldPtr); QT_RETHROW; } -- 2.11.0