summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype_p.h
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-12-20 17:11:46 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-16 02:00:15 +0100
commit214e031d56714ba69ef929f1e763e243b393e460 (patch)
tree4732bd79e015eecb85e66ba3a3facc58d5fba9ae /src/corelib/kernel/qmetatype_p.h
parentb9eb3715f55378802a1a0ae2f61d799ab84ee49a (diff)
Implement new static less API for QMetaType.
Currently QMetaType API contains almost only static methods. This works nice until someone needs more information or needs to do more operations on a type. In this case every function call has to do type dispatch. This API allows to avoid redundant type dispatching, by caching a type information in a QMetaType instance. It gives significant performance boost especially for custom types (up to 9x). Change-Id: I223d066268402e072e41ca1d0a3e7bc160655d7f Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qmetatype_p.h')
-rw-r--r--src/corelib/kernel/qmetatype_p.h43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index b1edc350a1..e48c5d3033 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -132,10 +132,8 @@ public:
}
static void deleter(T *t) { delete t; }
- #ifndef QT_NO_DATASTREAM
static void saver(QDataStream &stream, const T *t) { stream << *t; }
static void loader(QDataStream &stream, T *t) { stream >> *t; }
- #endif // QT_NO_DATASTREAM
static void destructor(T *t)
{
Q_UNUSED(t) // Silence MSVC that warns for POD types.
@@ -151,10 +149,8 @@ public:
QMetaType::Creator creator;
QMetaType::Deleter deleter;
-#ifndef QT_NO_DATASTREAM
QMetaType::SaveOperator saveOp;
QMetaType::LoadOperator loadOp;
-#endif
QMetaType::Constructor constructor;
QMetaType::Destructor destructor;
int size;
@@ -165,10 +161,8 @@ template<>
struct QMetaTypeInterface::Impl<void> {
static void *creator(const void *) { return 0; }
static void deleter(void *) {}
-#ifndef QT_NO_DATASTREAM
static void saver(QDataStream &, const void *) {}
static void loader(QDataStream &, void *) {}
-#endif // QT_NO_DATASTREAM
static void destructor(void *){}
static void *constructor(void *, const void *) { return 0; }
};
@@ -177,15 +171,22 @@ struct QMetaTypeInterface::Impl<void> {
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
/*loadOp*/(reinterpret_cast<QMetaType::LoadOperator>(QMetaTypeInterface::Impl<Type>::loader)),
+# define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
+ /*saveOp*/ 0, \
+ /*loadOp*/ 0,
#else
-# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type)
+# define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \
+ /*saveOp*/ 0, \
+ /*loadOp*/ 0,
+# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
+ QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type)
#endif
-#define QT_METATYPE_INTERFACE_INIT(Type) \
+#define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \
{ \
/*creator*/(reinterpret_cast<QMetaType::Creator>(QMetaTypeInterface::Impl<Type>::creator)), \
/*deleter*/(reinterpret_cast<QMetaType::Deleter>(QMetaTypeInterface::Impl<Type>::deleter)), \
- QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
+ DATASTREAM_DELEGATE(Type) \
/*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
/*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
/*size*/(QTypeInfo<Type>::sizeOf), \
@@ -194,6 +195,30 @@ struct QMetaTypeInterface::Impl<void> {
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsDestruction) \
}
+
+/* These QT_METATYPE_INTERFACE_INIT* macros are used to initialize QMetaTypeInterface instance.
+
+ - QT_METATYPE_INTERFACE_INIT(Type) -> It takes Type argument and creates all necessary wrapper functions for the Type,
+ it detects if QT_NO_DATASTREAM was defined. Probably it is the macro that you want to use.
+
+ - QT_METATYPE_INTERFACE_INIT_EMPTY() -> It initializes an empty QMetaTypeInterface instance.
+
+ - QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) -> Temporary workaround for missing auto-detection of data stream
+ operators. It creates same instance as QT_METATYPE_INTERFACE_INIT(Type) but with null stream operators callbacks.
+ */
+#define QT_METATYPE_INTERFACE_INIT(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL)
+#define QT_METATYPE_INTERFACE_INIT_NO_DATASTREAM(Type) QT_METATYPE_INTERFACE_INIT_IMPL(Type, QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL)
+#define QT_METATYPE_INTERFACE_INIT_EMPTY() \
+{ \
+ /*creator*/ 0, \
+ /*deleter*/ 0, \
+ QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL() \
+ /*constructor*/ 0, \
+ /*destructor*/ 0, \
+ /*size*/ 0, \
+ /*flags*/ 0 \
+}
+
QT_END_NAMESPACE
#endif // QMETATYPE_P_H