From 5d8f6b49d24df83af40727260c64c6d0399da0b0 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 20 Jul 2016 15:24:37 +0200 Subject: 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 --- src/qml/qml/qqmlengine.cpp | 2 ++ src/qml/qml/qqmlobjectcreator.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/qml/qml') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index e4e7530af7..5cfb546718 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1713,6 +1713,8 @@ void QQmlData::destroyed(QObject *object) if (ownMemory) delete this; + else + this->~QQmlData(); } DEFINE_BOOL_CONFIG_OPTION(parentTest, QML_PARENT_TEST); 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(reinterpret_cast(instance) + parserStatusCast); -- cgit v1.2.3