Don't needlessly create alias property names in the meta-object
authorKent Hansen <kent.hansen@nokia.com>
Mon, 5 Mar 2012 11:23:19 +0000 (12:23 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 7 Mar 2012 11:10:38 +0000 (12:10 +0100)
When aliases should not be resolved, there is no need to create the
alias name StringRef, since it would occupy space in the meta-data
even though the string was never actually initialized.

Similarly, when aliases should be resolved, it's enough to create the
StringRef once.

Change-Id: I44dfe665fe8d7bd5754bc939ff62ad75efe19d5b
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/qml/qml/ftw/qfastmetabuilder.cpp
src/qml/qml/qqmlcompiler.cpp

index 02f5091..08ea76b 100644 (file)
@@ -197,7 +197,8 @@ void QFastMetaBuilder::setProperty(int index, const StringRef &name, const Strin
                                    QMetaType::Type mtype, PropertyFlag flags, int notifySignal)
 {
     Q_ASSERT(!m_data.isEmpty());
-    Q_ASSERT(!name.isEmpty() && !type.isEmpty());
+    Q_ASSERT(!name.isEmpty());
+    Q_ASSERT(!type.isEmpty());
 
     QMetaObjectPrivate *p = priv(m_data);
     Q_ASSERT(index < p->propertyCount);
index 23c4adc..1ae8240 100644 (file)
@@ -2865,7 +2865,8 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
         for (Object::DynamicProperty *p = obj->dynamicProperties.first(); p; p = obj->dynamicProperties.next(p)) {
 
             // Reserve space for name
-            p->nameRef = builder.newString(p->name.utf8length());
+            if (p->type != Object::DynamicProperty::Alias || resolveAlias)
+                p->nameRef = builder.newString(p->name.utf8length());
 
             int propertyType = 0;
             bool readonly = false;
@@ -3231,6 +3232,8 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
                                         int propIndex, int aliasIndex,
                                         Object::DynamicProperty &prop)
 {
+    Q_ASSERT(!prop.nameRef.isEmpty());
+    Q_ASSERT(prop.typeRef.isEmpty());
     if (!prop.defaultValue)
         COMPILE_EXCEPTION(obj, tr("No property alias location"));
 
@@ -3325,7 +3328,6 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
     VMD *vmd = (QQmlVMEMetaData *)data.data();
     *(vmd->aliasData() + aliasIndex) = aliasData;
 
-    prop.nameRef = builder.newString(prop.name.utf8length());
     prop.resolvedCustomTypeName = pool->NewByteArray(typeName);
     prop.typeRef = builder.newString(typeName.length());