diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-02-11 07:02:13 +0100 |
---|---|---|
committer | Jędrzej Nowacki <jedrzej.nowacki@digia.com> | 2014-10-31 12:17:57 +0100 |
commit | 0678d7c43c1658d2d2ec984be5844054031649a2 (patch) | |
tree | 4d31d02a75ab78befa8553abbe1de26a4ed3e848 /tests/benchmarks | |
parent | 3de0f442b5857915f26be6600bc8e54d1af08208 (diff) |
Add QMetaType::type(QByteArray) function
QMetaType::type(const char *) requires that the string argument is
0-terminated. This new overload makes it possible to query the type
of a string with an explicit length.
In particular, QByteArrays constructed by QByteArray::fromRawData(),
for example from a substring of a normalized method signature (the
"int" part of "mySlot(int"), can now be queried without making a copy
of the string.
Also, Qt5 meta-objects represent type names as QByteArray literals,
which can be fed directly to this new QMetaType::type() overload (no
need to call strlen).
Change-Id: I60d35aa6bdc0f77e0997f98b0e30e12fd3d5e100
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/benchmarks')
-rw-r--r-- | tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp index 9403c3fbb4..53cf26d0f1 100644 --- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -45,6 +45,8 @@ public: private slots: void typeBuiltin_data(); void typeBuiltin(); + void typeBuiltin_QByteArray_data(); + void typeBuiltin_QByteArray(); void typeBuiltinNotNormalized_data(); void typeBuiltinNotNormalized(); void typeCustom(); @@ -94,6 +96,7 @@ void tst_QMetaType::typeBuiltin_data() } } +// QMetaType::type(const char *) void tst_QMetaType::typeBuiltin() { QFETCH(QByteArray, typeName); @@ -104,6 +107,21 @@ void tst_QMetaType::typeBuiltin() } } +void tst_QMetaType::typeBuiltin_QByteArray_data() +{ + typeBuiltin_data(); +} + +// QMetaType::type(QByteArray) +void tst_QMetaType::typeBuiltin_QByteArray() +{ + QFETCH(QByteArray, typeName); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::type(typeName); + } +} + void tst_QMetaType::typeBuiltinNotNormalized_data() { QTest::addColumn<QByteArray>("typeName"); |