summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-07-10 14:06:36 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-24 00:17:04 +0200
commit6754198c338abd560f3af31ff09630e0f1085843 (patch)
tree4354bf6840007f90c6187adc5e0a33e39f2fdcf3 /src/corelib/kernel/qvariant_p.h
parent76e8e8e9c8093f093cb9f37d61d273f43398fefb (diff)
Cleanup QVariant::PrivateShared
Remove the additional indirection through ptr and replace it with an offset calculation. Get rid of PrivateSharedEx that was handling certain types differently. This also fixes the support for overaligned types, by using the alignment field from QMetaType to determine the alignment requirements. Change-Id: Icc6a78eb57f664c7747450578fe58dfee8f2863b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qvariant_p.h')
-rw-r--r--src/corelib/kernel/qvariant_p.h25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index f92f97d836..926e95386f 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -89,7 +89,7 @@ template <typename T>
inline const T *v_cast(const QVariant::Private *d, T * = nullptr)
{
return !QVariantIntegrator<T>::CanUseInternalSpace
- ? static_cast<const T *>(d->data.shared->ptr)
+ ? static_cast<const T *>(d->data.shared->data())
: static_cast<const T *>(static_cast<const void *>(&d->data.c));
}
@@ -97,7 +97,7 @@ template <typename T>
inline T *v_cast(QVariant::Private *d, T * = nullptr)
{
return !QVariantIntegrator<T>::CanUseInternalSpace
- ? static_cast<T *>(d->data.shared->ptr)
+ ? static_cast<T *>(d->data.shared->data())
: static_cast<T *>(static_cast<void *>(&d->data.c));
}
@@ -108,17 +108,6 @@ enum QVariantConstructionFlags : uint {
PointerType = 0x1
};
-//a simple template that avoids to allocate 2 memory chunks when creating a QVariant
-template <class T> class QVariantPrivateSharedEx : public QVariant::PrivateShared
-{
-public:
- QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t), m_t() { }
- QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { }
-
-private:
- T m_t;
-};
-
template <class T>
inline void v_construct_helper(QVariant::Private *x, const T &t, std::true_type)
{
@@ -129,7 +118,8 @@ inline void v_construct_helper(QVariant::Private *x, const T &t, std::true_type)
template <class T>
inline void v_construct_helper(QVariant::Private *x, const T &t, std::false_type)
{
- x->data.shared = new QVariantPrivateSharedEx<T>(t);
+ x->data.shared = QVariant::PrivateShared::create(QMetaType::fromType<T>());
+ new (x->data.shared->data()) T(t);
x->is_shared = true;
}
@@ -143,7 +133,8 @@ inline void v_construct_helper(QVariant::Private *x, std::true_type)
template <class T>
inline void v_construct_helper(QVariant::Private *x, std::false_type)
{
- x->data.shared = new QVariantPrivateSharedEx<T>;
+ x->data.shared = QVariant::PrivateShared::create(QMetaType::fromType<T>());
+ new (x->data.shared->data()) T();
x->is_shared = true;
}
@@ -170,9 +161,7 @@ inline void v_clear(QVariant::Private *d, T* = nullptr)
{
if (!QVariantIntegrator<T>::CanUseInternalSpace) {
- //now we need to cast
- //because QVariant::PrivateShared doesn't have a virtual destructor
- delete static_cast<QVariantPrivateSharedEx<T>*>(d->data.shared);
+ delete static_cast<T *>(d->data.shared->data());
} else {
v_cast<T>(d)->~T();
}