Provide versions of qRegisterMetaType() that do not normalize typename.
QML is quite capable of providing typenames in the correct format. qRegisterNormalizedMetaType() does not normalize the typename, so avoids the huge overhead. Change-Id: I96c9a42fe0b5d36ac05a9247f6507dbf9583fa67 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
This commit is contained in:
parent
7e9f7080b7
commit
1946740446
@ -441,16 +441,37 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
|
||||
int size, TypeFlags flags, const QMetaObject *metaObject)
|
||||
{
|
||||
Q_UNUSED(metaObject);
|
||||
QVector<QCustomTypeInfo> *ct = customTypes();
|
||||
if (!ct || !typeName || !deleter || !creator || !destructor || !constructor)
|
||||
return -1;
|
||||
|
||||
#ifdef QT_NO_QOBJECT
|
||||
NS(QByteArray) normalizedTypeName = typeName;
|
||||
#else
|
||||
NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
|
||||
#endif
|
||||
|
||||
return registerNormalizedType(normalizedTypeName, deleter, creator, destructor, constructor, size, flags, metaObject);
|
||||
}
|
||||
|
||||
|
||||
/*! \internal
|
||||
\since 5.0
|
||||
|
||||
Registers a user type for marshalling, with \a normalizedTypeName, a \a
|
||||
deleter, a \a creator, a \a destructor, a \a constructor, and
|
||||
a \a size. Returns the type's handle, or -1 if the type could
|
||||
not be registered. Note that normalizedTypeName is not checked for
|
||||
conformance with Qt's normalized format, so it must already
|
||||
conform.
|
||||
*/
|
||||
int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, Deleter deleter,
|
||||
Creator creator,
|
||||
Destructor destructor,
|
||||
Constructor constructor,
|
||||
int size, TypeFlags flags, const QMetaObject *metaObject)
|
||||
{
|
||||
Q_UNUSED(metaObject);
|
||||
QVector<QCustomTypeInfo> *ct = customTypes();
|
||||
if (!ct || normalizedTypeName.isEmpty() || !deleter || !creator || !destructor || !constructor)
|
||||
return -1;
|
||||
|
||||
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
|
||||
normalizedTypeName.size());
|
||||
|
||||
@ -513,16 +534,28 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
|
||||
*/
|
||||
int QMetaType::registerTypedef(const char* typeName, int aliasId)
|
||||
{
|
||||
QVector<QCustomTypeInfo> *ct = customTypes();
|
||||
if (!ct || !typeName)
|
||||
return -1;
|
||||
|
||||
#ifdef QT_NO_QOBJECT
|
||||
NS(QByteArray) normalizedTypeName = typeName;
|
||||
#else
|
||||
NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
|
||||
#endif
|
||||
|
||||
return registerNormalizedTypedef(normalizedTypeName, aliasId);
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
\since 5.0
|
||||
|
||||
Registers a user type for marshalling, as an alias of another type (typedef).
|
||||
Note that normalizedTypeName is not checked for conformance with Qt's normalized format,
|
||||
so it must already conform.
|
||||
*/
|
||||
int QMetaType::registerNormalizedTypedef(const NS(QByteArray) &normalizedTypeName, int aliasId)
|
||||
{
|
||||
QVector<QCustomTypeInfo> *ct = customTypes();
|
||||
if (!ct || normalizedTypeName.isEmpty())
|
||||
return -1;
|
||||
|
||||
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
|
||||
normalizedTypeName.size());
|
||||
|
||||
|
@ -46,7 +46,9 @@
|
||||
#include <QtCore/qatomic.h>
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qisenum.h>
|
||||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
#include <QtCore/qobjectdefs.h>
|
||||
#endif
|
||||
#include <new>
|
||||
|
||||
#ifdef Bool
|
||||
@ -270,7 +272,15 @@ public:
|
||||
int size,
|
||||
QMetaType::TypeFlags flags,
|
||||
const QMetaObject *metaObject);
|
||||
static int registerNormalizedType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, Deleter deleter,
|
||||
Creator creator,
|
||||
Destructor destructor,
|
||||
Constructor constructor,
|
||||
int size,
|
||||
QMetaType::TypeFlags flags,
|
||||
const QMetaObject *metaObject);
|
||||
static int registerTypedef(const char *typeName, int aliasId);
|
||||
static int registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, int aliasId);
|
||||
static int type(const char *typeName);
|
||||
static const char *typeName(int type);
|
||||
static int sizeOf(int type);
|
||||
@ -505,7 +515,7 @@ namespace QtPrivate {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int qRegisterMetaType(const char *typeName
|
||||
int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName
|
||||
#ifndef qdoc
|
||||
, T * dummy = 0
|
||||
#endif
|
||||
@ -513,10 +523,10 @@ int qRegisterMetaType(const char *typeName
|
||||
{
|
||||
const int typedefOf = dummy ? -1 : QtPrivate::QMetaTypeIdHelper<T>::qt_metatype_id();
|
||||
if (typedefOf != -1)
|
||||
return QMetaType::registerTypedef(typeName, typedefOf);
|
||||
return QMetaType::registerNormalizedTypedef(normalizedTypeName, typedefOf);
|
||||
|
||||
QMetaType::TypeFlags flags(QtPrivate::QMetaTypeTypeFlags<T>::Flags);
|
||||
return QMetaType::registerType(typeName, qMetaTypeDeleteHelper<T>,
|
||||
return QMetaType::registerNormalizedType(normalizedTypeName, qMetaTypeDeleteHelper<T>,
|
||||
qMetaTypeCreateHelper<T>,
|
||||
qMetaTypeDestructHelper<T>,
|
||||
qMetaTypeConstructHelper<T>,
|
||||
@ -525,6 +535,21 @@ int qRegisterMetaType(const char *typeName
|
||||
QtPrivate::MetaObjectForType<T>::value());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int qRegisterMetaType(const char *typeName
|
||||
#ifndef qdoc
|
||||
, T * dummy = 0
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef QT_NO_QOBJECT
|
||||
QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = typeName;
|
||||
#else
|
||||
QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
|
||||
#endif
|
||||
return qRegisterNormalizedMetaType<T>(normalizedTypeName, dummy);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
template <typename T>
|
||||
void qRegisterMetaTypeStreamOperators(const char *typeName
|
||||
|
Loading…
Reference in New Issue
Block a user