QVariant::Private: replace QMetaType constructor with interface

And move it into the .cpp file, to hide the ugliness.

Change-Id: I3859764fed084846bcb0fffd17044729e361a42e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
bb10
Thiago Macieira 2022-07-22 15:26:48 -07:00
parent 3da89227fe
commit 36b4aa1118
2 changed files with 9 additions and 9 deletions

View File

@ -298,6 +298,12 @@ static QVariant::Private clonePrivate(const QVariant::Private &other)
} // anonymous used to hide QVariant handlers
inline QVariant::Private::Private(const QtPrivate::QMetaTypeInterface *iface) noexcept
: is_shared(false), is_null(false), packedType(quintptr(iface) >> 2)
{
Q_ASSERT((quintptr(iface) & 0x3) == 0);
}
template <typename T> inline
QVariant::Private::Private(std::piecewise_construct_t, const T &t)
: is_shared(!CanUseInternalSpace<T>), is_null(std::is_same_v<T, std::nullptr_t>)
@ -826,7 +832,7 @@ QVariant::QVariant(const QVariant &p)
\sa QVariant::fromValue(), QMetaType::Type
*/
QVariant::QVariant(QMetaType type, const void *copy) : d(type)
QVariant::QVariant(QMetaType type, const void *copy) : d(type.iface())
{
if (isValidMetaTypeForVariant(type.iface(), copy))
customConstruct(type.iface(), &d, copy);
@ -978,7 +984,7 @@ void QVariant::detach()
return;
Q_ASSERT(isValidMetaTypeForVariant(d.typeInterface(), constData()));
Private dd(d.type());
Private dd(d.typeInterface());
customConstruct(d.typeInterface(), &dd, constData());
if (!d.data.shared->ref.deref())
customClear(&d);

View File

@ -446,14 +446,8 @@ public:
quintptr packedType : sizeof(QMetaType) * 8 - 2;
constexpr Private() noexcept : is_shared(false), is_null(true), packedType(0) {}
explicit Private(const QtPrivate::QMetaTypeInterface *iface) noexcept;
template <typename T> explicit Private(std::piecewise_construct_t, const T &t);
explicit Private(QMetaType type) noexcept : is_shared(false), is_null(false)
{
quintptr mt = quintptr(type.d_ptr);
Q_ASSERT((mt & 0x3) == 0);
packedType = mt >> 2;
}
explicit Private(int type) noexcept : Private(QMetaType(type)) {}
const void *storage() const
{ return is_shared ? data.shared->data() : &data.data; }