From a1c5296a9feb7dd6c50b217c6ea68ad062884aab Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 12 Mar 2010 14:54:36 +1000 Subject: Make QML the object allocator more flexible By allocating memory internally we improve the opportunity for optimization. --- src/declarative/qml/qdeclarative.h | 25 +++++-------------------- src/declarative/qml/qdeclarativemetatype.cpp | 12 +++++++++--- src/declarative/qml/qdeclarativeprivate.h | 6 +++++- src/declarative/qml/qdeclarativevaluetype.cpp | 2 +- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/declarative/qml/qdeclarative.h b/src/declarative/qml/qdeclarative.h index 2a7a9cf..dfdef11 100644 --- a/src/declarative/qml/qdeclarative.h +++ b/src/declarative/qml/qdeclarative.h @@ -99,7 +99,7 @@ int qmlRegisterType() qRegisterMetaType(pointerName.constData()), qRegisterMetaType >(listName.constData()), - 0, + 0, 0, 0, 0, 0, 0, &T::staticMetaObject, @@ -131,7 +131,7 @@ int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const c qRegisterMetaType(pointerName.constData()), qRegisterMetaType >(listName.constData()), - QDeclarativePrivate::create, + sizeof(T), QDeclarativePrivate::createInto, uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, @@ -163,7 +163,7 @@ int qmlRegisterExtendedType() qRegisterMetaType(pointerName.constData()), qRegisterMetaType >(listName.constData()), - 0, + 0, 0, 0, 0, 0, 0, &T::staticMetaObject, @@ -203,7 +203,7 @@ int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, qRegisterMetaType(pointerName.constData()), qRegisterMetaType >(listName.constData()), - QDeclarativePrivate::create, + sizeof(T), QDeclarativePrivate::createInto, uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, @@ -256,7 +256,7 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, qRegisterMetaType(pointerName.constData()), qRegisterMetaType >(listName.constData()), - QDeclarativePrivate::create, + sizeof(T), QDeclarativePrivate::createInto, uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, @@ -275,21 +275,6 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor, return QDeclarativePrivate::registerType(type); } -#if 0 -#define QML_REGISTER_INTERFACE(INTERFACE) \ - qmlRegisterInterface(#INTERFACE) - -#define QML_REGISTER_EXTENDED_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, CLASS, EXTENSION) \ - qmlRegisterExtendedType(#URI, VERSION_MAJ, VERSION_MIN, #NAME) - -#define QML_REGISTER_TYPE(URI,VMAJ,VMIN,NAME,CLASS) \ - qmlRegisterType(#URI, VMAJ, VMIN, #NAME) - -#define QML_REGISTER_NOCREATE_TYPE(CLASS) \ - qmlRegisterType() - -#endif - class QDeclarativeContext; class QDeclarativeEngine; Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *); diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 50ab56b..55c7413 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -124,7 +124,10 @@ public: int m_version_maj; int m_version_min; int m_typeId; int m_listId; - QObject *(*m_newFunc)(); + + int m_allocationSize; + void (*m_newFunc)(void *); + const QMetaObject *m_baseMetaObject; QDeclarativeAttachedPropertiesFunc m_attachedPropertiesFunc; const QMetaObject *m_attachedPropertiesType; @@ -141,7 +144,7 @@ public: QDeclarativeTypePrivate::QDeclarativeTypePrivate() : m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), - m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), + m_allocationSize(0), m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), m_parserStatusCast(-1), m_propertyValueSourceCast(-1), m_propertyValueInterceptorCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1), m_customParser(0), m_isSetup(false) { @@ -174,6 +177,7 @@ QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::Registe d->m_version_min = type.versionMinor; d->m_typeId = type.typeId; d->m_listId = type.listId; + d->m_allocationSize = type.objectSize; d->m_newFunc = type.create; d->m_baseMetaObject = type.metaObject; d->m_attachedPropertiesFunc = type.attachedPropertiesFunction; @@ -274,7 +278,9 @@ QObject *QDeclarativeType::create() const { d->init(); - QObject *rv = d->m_newFunc(); + QObject *rv = (QObject *)operator new(d->m_allocationSize); + d->m_newFunc(rv); + if (rv && !d->m_metaObjects.isEmpty()) (void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects); diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h index 01369d4..bebe82c 100644 --- a/src/declarative/qml/qdeclarativeprivate.h +++ b/src/declarative/qml/qdeclarativeprivate.h @@ -73,6 +73,9 @@ namespace QDeclarativePrivate QObject *create() { return new T; } template + void createInto(void *memory) { new (memory) T; } + + template QObject *createParent(QObject *p) { return new T(p); } template @@ -172,7 +175,8 @@ namespace QDeclarativePrivate int typeId; int listId; - QObject *(*create)(); + int objectSize; + void (*create)(void *); const char *uri; int versionMajor; diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index c070123..00e6704 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -61,7 +61,7 @@ int qmlRegisterValueTypeEnums(const char *qmlName) QDeclarativePrivate::RegisterType type = { 0, - qRegisterMetaType(pointerName.constData()), 0, 0, + qRegisterMetaType(pointerName.constData()), 0, 0, 0, "Qt", 4, 6, qmlName, &T::staticMetaObject, -- cgit v0.12