QVariant: simple improvement to numeric type checking
Results in faster code. Change-Id: Ibeeac8c0f9d8a525fa233e00301338d3170ee413 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
This commit is contained in:
parent
38174159be
commit
34b66aaf07
@ -3160,9 +3160,22 @@ bool QVariant::convert(const int type, void *ptr) const
|
||||
|
||||
static bool qIsNumericType(uint tp)
|
||||
{
|
||||
return (tp >= QVariant::Bool && tp <= QVariant::Double)
|
||||
|| (tp >= QMetaType::Long && tp <= QMetaType::Float)
|
||||
|| tp == QMetaType::SChar;
|
||||
static const qulonglong numericTypeBits =
|
||||
Q_UINT64_C(1) << QMetaType::Bool |
|
||||
Q_UINT64_C(1) << QMetaType::Double |
|
||||
Q_UINT64_C(1) << QMetaType::Float |
|
||||
Q_UINT64_C(1) << QMetaType::Char |
|
||||
Q_UINT64_C(1) << QMetaType::SChar |
|
||||
Q_UINT64_C(1) << QMetaType::UChar |
|
||||
Q_UINT64_C(1) << QMetaType::Short |
|
||||
Q_UINT64_C(1) << QMetaType::UShort |
|
||||
Q_UINT64_C(1) << QMetaType::Int |
|
||||
Q_UINT64_C(1) << QMetaType::UInt |
|
||||
Q_UINT64_C(1) << QMetaType::Long |
|
||||
Q_UINT64_C(1) << QMetaType::ULong |
|
||||
Q_UINT64_C(1) << QMetaType::LongLong |
|
||||
Q_UINT64_C(1) << QMetaType::ULongLong;
|
||||
return tp < (CHAR_BIT * sizeof numericTypeBits) ? numericTypeBits & (Q_UINT64_C(1) << tp) : false;
|
||||
}
|
||||
|
||||
static bool qIsFloatingPoint(uint tp)
|
||||
@ -3172,11 +3185,14 @@ static bool qIsFloatingPoint(uint tp)
|
||||
|
||||
static int normalizeLowerRanks(uint tp)
|
||||
{
|
||||
if (tp == QVariant::Bool
|
||||
|| tp == QVariant::Char || tp == QMetaType::SChar || tp == QMetaType::UChar
|
||||
|| tp == QMetaType::Short || tp == QMetaType::UShort)
|
||||
return QVariant::Int;
|
||||
return tp;
|
||||
static const qulonglong numericTypeBits =
|
||||
Q_UINT64_C(1) << QMetaType::Bool |
|
||||
Q_UINT64_C(1) << QMetaType::Char |
|
||||
Q_UINT64_C(1) << QMetaType::SChar |
|
||||
Q_UINT64_C(1) << QMetaType::UChar |
|
||||
Q_UINT64_C(1) << QMetaType::Short |
|
||||
Q_UINT64_C(1) << QMetaType::UShort;
|
||||
return numericTypeBits & (Q_UINT64_C(1) << tp) ? QVariant::Int : tp;
|
||||
}
|
||||
|
||||
static int normalizeLong(uint tp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user