summaryrefslogtreecommitdiff
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-11-30 09:57:56 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-11 08:10:14 +0100
commita13a2d6b618e0f55dc09e7b4322e00ec9d56096f (patch)
tree1fbb40fd24a66d29173f19ef8b3e277396554906 /src/corelib/tools
parent8de6762112640bf5ddb975115f9a60db91ce73af (diff)
downloadqtbase-a13a2d6b618e0f55dc09e7b4322e00ec9d56096f.tar.gz
QVLA: separate control from inline storage [3/N]: Extract Further Base Class
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 <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qvarlengtharray.h27
1 files 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<Size, Align> array[Prealloc];
};
-template<class T>
-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 T>
+class QVLABase : public QVLABaseBase
+{
+protected:
+ ~QVLABase() = default;
+
+public:
+ T *data() noexcept { return static_cast<T *>(ptr); }
+ const T *data() const noexcept { return static_cast<T *>(ptr); }
using iterator = T*;
using const_iterator = const T*;