summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-12 04:54:36 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-12 04:54:36 (GMT)
commita1c5296a9feb7dd6c50b217c6ea68ad062884aab (patch)
treebfcffd02403b8cb9a3b128fc1714c18e9c075223 /src
parentdf861cb0f6d6ae0b6971342adc199be7d7ec6009 (diff)
downloadQt-a1c5296a9feb7dd6c50b217c6ea68ad062884aab.zip
Qt-a1c5296a9feb7dd6c50b217c6ea68ad062884aab.tar.gz
Qt-a1c5296a9feb7dd6c50b217c6ea68ad062884aab.tar.bz2
Make QML the object allocator more flexible
By allocating memory internally we improve the opportunity for optimization.
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarative.h25
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp12
-rw-r--r--src/declarative/qml/qdeclarativeprivate.h6
-rw-r--r--src/declarative/qml/qdeclarativevaluetype.cpp2
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<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(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<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
@@ -163,7 +163,7 @@ int qmlRegisterExtendedType()
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(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<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
@@ -256,7 +256,7 @@ int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor,
qRegisterMetaType<T *>(pointerName.constData()),
qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
- QDeclarativePrivate::create<T>,
+ sizeof(T), QDeclarativePrivate::createInto<T>,
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>(#INTERFACE)
-
-#define QML_REGISTER_EXTENDED_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, CLASS, EXTENSION) \
- qmlRegisterExtendedType<CLASS,EXTENSION>(#URI, VERSION_MAJ, VERSION_MIN, #NAME)
-
-#define QML_REGISTER_TYPE(URI,VMAJ,VMIN,NAME,CLASS) \
- qmlRegisterType<CLASS>(#URI, VMAJ, VMIN, #NAME)
-
-#define QML_REGISTER_NOCREATE_TYPE(CLASS) \
- qmlRegisterType<CLASS>()
-
-#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<typename T>
+ void createInto(void *memory) { new (memory) T; }
+
+ template<typename T>
QObject *createParent(QObject *p) { return new T(p); }
template<class From, class To, int N>
@@ -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<T *>(pointerName.constData()), 0, 0,
+ qRegisterMetaType<T *>(pointerName.constData()), 0, 0, 0,
"Qt", 4, 6, qmlName, &T::staticMetaObject,