diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-02-25 16:36:41 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-02 14:48:43 +0100 |
commit | 963875db263e4d1a04e03c4bb4fc20542bc8c21e (patch) | |
tree | cbb63607672e9d302d30389c8fe7553b27807b1f /src/qml/compiler/qqmlcodegenerator_p.h | |
parent | 278ca02350c68a78c89bb34d99ee65968372a5fd (diff) |
[new compiler] Compile functions and bindings in appropriate scopes
This enables accelerated property access also for this code path.
Change-Id: Iafb177b1fe7878e6c54cfb258f2e8d8ea32aa59e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qqmlcodegenerator_p.h')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 7f27bded20..304df224c0 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -136,6 +136,49 @@ struct PoolList ++count; } } + + T *slowAt(int index) const + { + T *result = first; + while (index > 0 && result) { + result = result->next; + --index; + } + return result; + } +}; + +template <typename T> +class FixedPoolArray +{ + T *data; + int count; +public: + + void init(QQmlJS::MemoryPool *pool, const QVector<T> &vector) + { + count = vector.count(); + data = reinterpret_cast<T*>(pool->allocate(count * sizeof(T))); + + if (QTypeInfo<T>::isComplex) { + for (int i = 0; i < count; ++i) + new (data + i) T(vector.at(i)); + } else { + memcpy(data, static_cast<const void*>(vector.constData()), count * sizeof(T)); + } + } + + const T &at(int index) const { + Q_ASSERT(index >= 0 && index < count); + return data[index]; + } + + int indexOf(const T &value) const { + for (int i = 0; i < count; ++i) + if (data[i] == value) + return i; + return -1; + } }; struct QmlObject; @@ -163,7 +206,7 @@ struct QmlProperty : public QV4::CompiledData::Property struct Binding : public QV4::CompiledData::Binding { - // Binding's compiledScriptIndex is index in parsedQML::functions + // Binding's compiledScriptIndex is index in object's functionsAndExpressions Binding *next; }; @@ -172,7 +215,7 @@ struct Function QQmlJS::AST::FunctionDeclaration *functionDeclaration; QV4::CompiledData::Location location; int nameIndex; - int index; // index in parsedQML::functions + quint32 index; // index in parsedQML::functions Function *next; }; @@ -180,15 +223,20 @@ struct CompiledFunctionOrExpression { CompiledFunctionOrExpression() : node(0) + , nameIndex(0) , disableAcceleratedLookups(false) + , next(0) {} CompiledFunctionOrExpression(QQmlJS::AST::Node *n) : node(n) + , nameIndex(0) , disableAcceleratedLookups(false) + , next(0) {} QQmlJS::AST::Node *node; // FunctionDeclaration, Statement or Expression - QString name; + quint32 nameIndex; bool disableAcceleratedLookups; + CompiledFunctionOrExpression *next; }; struct QmlObject @@ -219,7 +267,7 @@ public: void dump(DebugStream &out); - QString sanityCheckFunctionNames(const QList<CompiledFunctionOrExpression> &allFunctions, const QSet<QString> &illegalNames, QQmlJS::AST::SourceLocation *errorLocation); + QString sanityCheckFunctionNames(const QSet<QString> &illegalNames, QQmlJS::AST::SourceLocation *errorLocation); QString appendSignal(Signal *signal); QString appendProperty(QmlProperty *prop, const QString &propertyName, bool isDefaultProperty, const QQmlJS::AST::SourceLocation &defaultToken, QQmlJS::AST::SourceLocation *errorLocation); @@ -228,6 +276,9 @@ public: QString appendBinding(Binding *b, bool isListBinding); Binding *findBinding(quint32 nameIndex) const; + PoolList<CompiledFunctionOrExpression> *functionsAndExpressions; + FixedPoolArray<int> *runtimeFunctionIndices; + private: PoolList<QmlProperty> *properties; PoolList<Signal> *qmlSignals; @@ -259,7 +310,6 @@ struct ParsedQML QQmlJS::AST::UiProgram *program; int indexOfRootObject; QList<QmlObject*> objects; - QList<CompiledFunctionOrExpression> functions; QV4::Compiler::JSUnitGenerator jsGenerator; QV4::CompiledData::TypeReferenceMap typeReferences; @@ -350,7 +400,6 @@ public: QList<QV4::CompiledData::Import*> _imports; QList<Pragma*> _pragmas; QList<QmlObject*> _objects; - QList<CompiledFunctionOrExpression> _functions; QV4::CompiledData::TypeReferenceMap _typeReferences; @@ -370,11 +419,11 @@ struct Q_QML_EXPORT QmlUnitGenerator { } - QV4::CompiledData::QmlUnit *generate(ParsedQML &output, const QVector<int> &runtimeFunctionIndices); + QV4::CompiledData::QmlUnit *generate(ParsedQML &output); private: typedef bool (Binding::*BindingFilter)() const; - char *writeBindings(char *bindingPtr, QmlObject *o, const QVector<int> &runtimeFunctionIndices, BindingFilter filter) const; + char *writeBindings(char *bindingPtr, QmlObject *o, BindingFilter filter) const; int getStringId(const QString &str) const; @@ -430,7 +479,8 @@ private: struct Q_QML_EXPORT JSCodeGen : public QQmlJS::Codegen { JSCodeGen(const QString &fileName, const QString &sourceCode, IR::Module *jsModule, - QQmlJS::Engine *jsEngine, QQmlJS::AST::UiProgram *qmlRoot, QQmlTypeNameCache *imports); + QQmlJS::Engine *jsEngine, QQmlJS::AST::UiProgram *qmlRoot, QQmlTypeNameCache *imports, + const QStringList &stringPool); struct IdMapping { @@ -457,6 +507,7 @@ private: QQmlJS::Engine *jsEngine; // needed for memory pool QQmlJS::AST::UiProgram *qmlRoot; QQmlTypeNameCache *imports; + const QStringList &stringPool; bool _disableAcceleratedLookups; ObjectIdMapping _idObjects; |