aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlobjectcreator.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-07-20 15:24:37 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-08-03 15:11:21 +0000
commit5d8f6b49d24df83af40727260c64c6d0399da0b0 (patch)
tree4efdaa367b7beb71f4737d767093743f32276c0d /src/qml/qml/qqmlobjectcreator.cpp
parentc8978bd582eabf8deb139e2606317b0df0aa7ec2 (diff)
Reduce the amount of malloc calls when instantiating objects
For regular Qt types we currently perform three mallocs, one for the public class, one for the private and one for the declarative data. The latter we can fold quite easily into the malloc of the public class. The plan for the private is a bigger separate one ;-) Change-Id: I69973652ba70a4a238b491dff3d47a9db9a226f1 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlobjectcreator.cpp')
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 3000f3e695..b354104b6e 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -1039,12 +1039,20 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
if (type) {
Q_QML_OC_PROFILE(sharedState->profiler, profiler.update(
compilationUnit, obj, type->qmlTypeName(), context->url()));
- instance = type->create();
+
+ void *ddataMemory = 0;
+ type->create(&instance, &ddataMemory, sizeof(QQmlData));
if (!instance) {
recordError(obj->location, tr("Unable to create object of type %1").arg(stringAt(obj->inheritedTypeNameIndex)));
return 0;
}
+ {
+ QQmlData *ddata = new (ddataMemory) QQmlData;
+ ddata->ownMemory = false;
+ QObjectPrivate::get(instance)->declarativeData = ddata;
+ }
+
const int parserStatusCast = type->parserStatusCast();
if (parserStatusCast != -1)
parserStatus = reinterpret_cast<QQmlParserStatus*>(reinterpret_cast<char *>(instance) + parserStatusCast);