diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index ca724dbfac0..a2711a48f85 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -215,7 +215,7 @@ static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok) // the type of d has already been set, but other field are not set static void customConstruct(QVariant::Private *d, const void *copy) { - QtPrivate::QMetaTypeInterface *iface = d->typeInterface(); + const QtPrivate::QMetaTypeInterface *iface = d->typeInterface(); if (!(iface && iface->size)) { *d = QVariant::Private(); return; @@ -498,11 +498,8 @@ QVariant::QVariant(const QVariant &p) { if (d.is_shared) { d.data.shared->ref.ref(); - return; - } - QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); - auto other = p.constData(); - if (iface) { + } else if (const QtPrivate::QMetaTypeInterface *iface = d.typeInterface()) { + auto other = p.constData(); if (other) iface->copyCtr(iface, &d.data, other); else @@ -993,7 +990,7 @@ QVariant &QVariant::operator=(const QVariant &variant) d = variant.d; } else { d = variant.d; - QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); + const QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); const void *other = variant.constData(); if (iface) { if (other) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 2a9b92f0c8c..dc73f46af51 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -428,7 +428,7 @@ public: static constexpr size_t MaxInternalSize = 3*sizeof(void *); template static constexpr bool CanUseInternalSpace = (QTypeInfo::isRelocatable && sizeof(T) <= MaxInternalSize && alignof(T) <= alignof(double)); - static constexpr bool canUseInternalSpace(QtPrivate::QMetaTypeInterface *type) + static constexpr bool canUseInternalSpace(const QtPrivate::QMetaTypeInterface *type) { Q_ASSERT(type); return QMetaType::TypeFlags(type->flags) & QMetaType::RelocatableType && @@ -468,14 +468,14 @@ public: void set(const T &t) { *static_cast(CanUseInternalSpace ? &data.data : data.shared->data()) = t; } - inline QMetaType type() const + inline const QtPrivate::QMetaTypeInterface* typeInterface() const { - return QMetaType(reinterpret_cast(packedType << 2)); + return reinterpret_cast(packedType << 2); } - inline QtPrivate::QMetaTypeInterface * typeInterface() const + inline QMetaType type() const { - return reinterpret_cast(packedType << 2); + return QMetaType(typeInterface()); } inline int typeId() const