From e01f3e8b5a3b9f2133801f1de98b9e451782480d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 30 Nov 2021 16:35:06 +0100 Subject: [PATCH] QVLA: separate control from inline storage [4/N]: cleanup casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove some reinterpret_casts that became useless when we ported 'ptr' to be a 'void*'. Task-number: QTBUG-84785 Change-Id: I886304da50e18152abc664d2adf094617c37887f Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Fabian Kosmale --- src/corelib/tools/qvarlengtharray.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a9012df7d6..365be9d241 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -242,7 +242,7 @@ public: { this->a = Prealloc; this->s = 0; - this->ptr = reinterpret_cast(this->array); + this->ptr = this->array; } inline explicit QVarLengthArray(qsizetype size); @@ -260,7 +260,7 @@ public: const auto otherInlineStorage = reinterpret_cast(other.array); if (data() == otherInlineStorage) { // inline buffer - move into our inline buffer: - this->ptr = reinterpret_cast(this->array); + this->ptr = this->array; QtPrivate::q_uninitialized_relocate_n(otherInlineStorage, size(), data()); } else { // heap buffer - we just stole the memory @@ -308,7 +308,7 @@ public: // the moved-from state is the empty state, so we're good with the clear() here: clear(); Q_ASSERT(capacity() >= Prealloc); - const auto otherInlineStorage = reinterpret_cast(other.array); + const auto otherInlineStorage = other.array; if (other.ptr != otherInlineStorage) { // heap storage: steal the external buffer, reset other to otherInlineStorage this->a = std::exchange(other.a, Prealloc); @@ -596,11 +596,11 @@ Q_INLINE_TEMPLATE QVarLengthArray::QVarLengthArray(qsizetype asize) static_assert(Prealloc > 0, "QVarLengthArray Prealloc must be greater than 0."); Q_ASSERT_X(size() >= 0, "QVarLengthArray::QVarLengthArray()", "Size must be greater than or equal to 0."); if (size() > Prealloc) { - this->ptr = reinterpret_cast(malloc(size() * sizeof(T))); + this->ptr = malloc(size() * sizeof(T)); Q_CHECK_PTR(data()); this->a = size(); } else { - this->ptr = reinterpret_cast(this->array); + this->ptr = this->array; this->a = Prealloc; } if constexpr (QTypeInfo::isComplex) { @@ -694,19 +694,20 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray::reallocate(qsizetype asi void operator()(void *p) const noexcept { free(p); } }; std::unique_ptr guard; - T *newPtr; + void *newPtr; qsizetype newA; if (aalloc > Prealloc) { - newPtr = reinterpret_cast(malloc(aalloc * sizeof(T))); + newPtr = malloc(aalloc * sizeof(T)); guard.reset(newPtr); Q_CHECK_PTR(newPtr); // could throw // by design: in case of QT_NO_EXCEPTIONS malloc must not fail or it crashes here newA = aalloc; } else { - newPtr = reinterpret_cast(this->array); + newPtr = this->array; newA = Prealloc; } - QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize, newPtr); + QtPrivate::q_uninitialized_relocate_n(oldPtr, copySize, + reinterpret_cast(newPtr)); // commit: this->ptr = newPtr; guard.release();