From a13a2d6b618e0f55dc09e7b4322e00ec9d56096f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 30 Nov 2021 09:57:56 +0100 Subject: [PATCH] QVLA: separate control from inline storage [3/N]: Extract Further Base Class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out that some functionality (most prominently, the verify() function that contains the asserts), depends on nothing but the size member, so Extract QVLABaseBase, a non-template class, to hold the data members, and the size()- and capacity()-related member functions. Task-number: QTBUG-84785 Change-Id: Ic21855fd6147b67507c122b6f091b44a3ba997f5 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/corelib/tools/qvarlengtharray.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index fa5643ee7a..a9012df7d6 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -66,15 +66,14 @@ protected: std::aligned_storage_t array[Prealloc]; }; -template -class QVLABase +class QVLABaseBase { protected: - ~QVLABase() = default; + ~QVLABaseBase() = default; qsizetype a; // capacity qsizetype s; // size - T *ptr; // data + void *ptr; // data Q_ALWAYS_INLINE constexpr void verify(qsizetype pos = 0, qsizetype n = 1) const { @@ -85,14 +84,22 @@ protected: } public: - T *data() noexcept { return ptr; } - const T *data() const noexcept { return ptr; } - using size_type = qsizetype; - size_type capacity() const noexcept { return a; } - size_type size() const noexcept { return s; } - bool empty() const noexcept { return size() == 0; } + constexpr size_type capacity() const noexcept { return a; } + constexpr size_type size() const noexcept { return s; } + constexpr bool empty() const noexcept { return size() == 0; } +}; + +template +class QVLABase : public QVLABaseBase +{ +protected: + ~QVLABase() = default; + +public: + T *data() noexcept { return static_cast(ptr); } + const T *data() const noexcept { return static_cast(ptr); } using iterator = T*; using const_iterator = const T*;