From b6c8497cdf070c8404a1f3784c4ee6df191bd546 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 21 Dec 2011 16:34:36 +0000 Subject: Detect and optimize qsTr() and qsTrId() bindings As these two are frequently used with constants, we can detect them in the compiler, and run the appropriate C++ functions directly in the VME. This saves pointlessly creating and running bindings. Change-Id: I148a150400c13fda7955949453405202f18b1a6b Reviewed-by: Roberto Raggi --- src/declarative/qml/qdeclarativecompiler_p.h | 37 ++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/declarative/qml/qdeclarativecompiler_p.h') diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 77f5b860dc..c592fd9a63 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -179,23 +179,36 @@ namespace QDeclarativeCompilerTypes { QDeclarativeScript::Object *object; }; - struct BindingReference : public QDeclarativePool::Class + struct BindingReference { - BindingReference() : nextReference(0) {} + enum DataType { QtScript, V4, V8, + Tr, TrId }; + DataType dataType; + }; + + struct JSBindingReference : public QDeclarativePool::Class, + public BindingReference + { + JSBindingReference() : nextReference(0) {} QDeclarativeScript::Variant expression; QDeclarativeScript::Property *property; QDeclarativeScript::Value *value; - enum DataType { QtScript, V4, V8 }; - DataType dataType; - int compiledIndex; QString rewrittenExpression; BindingContext bindingContext; - BindingReference *nextReference; + JSBindingReference *nextReference; + }; + + struct TrBindingReference : public QDeclarativePool::POD, + public BindingReference + { + QStringRef text; + QStringRef comment; + int n; }; struct IdList : public QFieldList BindingReferenceList; - BindingReferenceList bindings; + typedef QDeclarativeCompilerTypes::JSBindingReference B; + typedef QFieldList JSBindingReferenceList; + JSBindingReferenceList bindings; typedef QDeclarativeScript::Object O; typedef QFieldList AliasingObjectsList; AliasingObjectsList aliasingObjects; @@ -347,6 +360,8 @@ private: bool checkDynamicMeta(QDeclarativeScript::Object *obj); bool buildBinding(QDeclarativeScript::Value *, QDeclarativeScript::Property *prop, const QDeclarativeCompilerTypes::BindingContext &ctxt); + bool buildLiteralBinding(QDeclarativeScript::Value *, QDeclarativeScript::Property *prop, + const QDeclarativeCompilerTypes::BindingContext &ctxt); bool buildComponentFromRoot(QDeclarativeScript::Object *obj, const QDeclarativeCompilerTypes::BindingContext &); bool compileAlias(QFastMetaBuilder &, QByteArray &data, @@ -378,6 +393,7 @@ private: QDeclarativeScript::Property *valueTypeProp); int componentTypeRef(); + int translationContextIndex(); static QDeclarativeType *toQmlType(QDeclarativeScript::Object *from); bool canCoerce(int to, QDeclarativeScript::Object *from); @@ -399,7 +415,7 @@ private: void dumpStats(); - void addBindingReference(QDeclarativeCompilerTypes::BindingReference *); + void addBindingReference(QDeclarativeCompilerTypes::JSBindingReference *); QDeclarativeCompilerTypes::ComponentCompileState *compileState; @@ -415,6 +431,7 @@ private: QDeclarativeScript::Object *unitRoot; QDeclarativeTypeData *unit; int cachedComponentTypeRef; + int cachedTranslationContextIndex; // Compiler component statistics. Only collected if QML_COMPILER_STATS=1 struct ComponentStat -- cgit v1.2.3