summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-11-17 18:18:55 -0800
committerThiago Macieira <thiago.macieira@intel.com>2014-12-03 18:09:10 +0100
commit34b66aaf07af57bb11b9abae9fb175f650540f95 (patch)
tree36a18549974ae75d60880a7c9d53cdbf4b599985 /src
parent38174159bea2dbc401fe92c30545acdf3ac4cf2f (diff)
QVariant: simple improvement to numeric type checking
Results in faster code. Change-Id: Ibeeac8c0f9d8a525fa233e00301338d3170ee413 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qvariant.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 1012d90bd8..1e71bb8978 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -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)