From 2d3b31171d8fce2ab364ca2ceea4e75020933334 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 14 Jul 2020 00:30:41 +0200 Subject: Get rid of the old QVariant conversion codepath All conversions do now happen through QMetaType::convert(). Change-Id: I70f7a883262087768acccf8361d34c0490ff2b43 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qmetatype.cpp | 18 +++++++++++- src/corelib/kernel/qvariant.cpp | 62 +++++----------------------------------- 2 files changed, 24 insertions(+), 56 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 4991cb748a..446511c14d 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1236,6 +1236,10 @@ static const struct : QMetaTypeModuleHelper result = QCborValue(QCborValue::Null); return true; ); + QMETATYPE_CONVERTER(Nullptr, QCborValue, + result = nullptr; + return source.isNull(); + ); QMETATYPE_CONVERTER_ASSIGN(QCborValue, Bool); QMETATYPE_CONVERTER_ASSIGN(QCborValue, Int); QMETATYPE_CONVERTER_ASSIGN(QCborValue, UInt); @@ -1423,7 +1427,12 @@ static const struct : QMetaTypeModuleHelper QMETATYPE_CONVERTER(QJsonValue, Nullptr, Q_UNUSED(source); result = QJsonValue(QJsonValue::Null); - return true;); + return true; + ); + QMETATYPE_CONVERTER(Nullptr, QJsonValue, + result = nullptr; + return source.isNull(); + ); QMETATYPE_CONVERTER(QJsonValue, Bool, result = QJsonValue(source); return true;); @@ -1842,6 +1851,13 @@ bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId QMetaType toType(toTypeId); if (toType.flags() & QMetaType::IsEnumeration) return convertToEnum(from, fromTypeId, to, toType); + if (toTypeId == Nullptr) { + *static_cast(to) = nullptr; + if (fromType.flags() & QMetaType::IsPointer) { + if (*static_cast(from) == nullptr) + return true; + } + } return false; } diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index f34e955082..4f0664dc28 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -245,36 +245,6 @@ static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok) } } -/*! - \internal - - Converts \a d to type \a t, which is placed in \a result. - */ -static bool convert(const QVariant::Private *d, int t, void *result) -{ - Q_ASSERT(d->typeId() != t); - Q_ASSERT(result); - - switch (uint(t)) { - case QMetaType::Nullptr: - *static_cast(result) = nullptr; - if (QMetaType::typeFlags(t) & (QMetaType::PointerToGadget | QMetaType::PointerToQObject) - || d->typeId() == QMetaType::VoidStar) { - if (d->get() == nullptr) - break; - } -#ifndef QT_BOOTSTRAPPED - if (d->typeId() == QMetaType::QCborValue && d->get().isNull()) - break; -#endif - return false; - - default: - return false; - } - return true; -} - // the type of d has already been set, but other field are not set static void customConstruct(QVariant::Private *d, const void *copy) { @@ -1391,11 +1361,7 @@ inline T qVariantToHelper(const QVariant::Private &d) return d.get(); T ret; - const void * const from = d.storage(); - if (QMetaType::convert(from, d.typeId(), &ret, targetType.id())) - return ret; - - convert(&d, targetType.id(), &ret); + QMetaType::convert(d.storage(), d.typeId(), &ret, targetType.id()); return ret; } @@ -1823,10 +1789,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, bool *ok, const T& val) return val; T ret = 0; - if (QMetaType::convert(d.storage(), d.typeId(), &ret, t)) - return ret; - - bool success = convert(&d, t, &ret); + bool success = QMetaType::convert(d.storage(), d.typeId(), &ret, t); if (ok) *ok = success; return ret; @@ -1928,12 +1891,7 @@ bool QVariant::toBool() const return d.get(); bool res = false; - - if (QMetaType::convert(constData(), d.typeId(), &res, QMetaType::Bool)) - return res; - - ::convert(&d, Bool, &res); - + QMetaType::convert(constData(), d.typeId(), &res, QMetaType::Bool); return res; } @@ -2469,13 +2427,9 @@ bool QVariant::convert(int targetTypeId) return true; } - bool isOk = false; - isOk = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId); - if (!isOk) - isOk = ::convert(&oldValue.d, targetTypeId, data()); - - d.is_null = !isOk; - return isOk; + bool ok = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId); + d.is_null = !ok; + return ok; } /*! @@ -2485,9 +2439,7 @@ bool QVariant::convert(int targetTypeId) */ bool QVariant::convert(const int type, void *ptr) const { - if (QMetaType::convert(constData(), d.typeId(), ptr, type)) - return true; - return ::convert(&d, type, ptr); + return QMetaType::convert(constData(), d.typeId(), ptr, type); } -- cgit v1.2.3