diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-10-09 00:24:55 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-11 22:55:02 +0200 |
commit | 774963f52f569e637f45d6c6079121253e54b61b (patch) | |
tree | b007dcdbe49a90db727593d4e1966c92d4622dee /src/qml/qml/qqmlcompiler.cpp | |
parent | c39393e7de5b808adbc9c5771ecca161c9660d7c (diff) |
Compile JS functions as part of the QQmlCompiler run in the loader thread
...instead of extracting the function body as a string and compiling it in the
GUI thread.
Change-Id: I3c3108f6e35464b5581a2d8b5799e7285858ce4d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlcompiler.cpp')
-rw-r--r-- | src/qml/qml/qqmlcompiler.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index afbec31cb5..d14c790aad 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -811,6 +811,7 @@ bool QQmlCompiler::compile(QQmlEngine *engine, this->unitRoot = root; this->output = out; this->functionsToCompile.clear(); + this->compiledMetaMethods.clear(); // Compile types const QList<QQmlTypeData::TypeReference> &resolvedTypes = unit->resolvedTypes(); @@ -955,6 +956,13 @@ void QQmlCompiler::compileTree(QQmlScript::Object *tree) } } + foreach (const CompiledMetaMethod &cmm, compiledMetaMethods) { + typedef QQmlVMEMetaData VMD; + VMD *vmd = (QQmlVMEMetaData *)cmm.obj->synthdata.data(); + VMD::MethodData &md = *(vmd->methodData() + cmm.methodIndex); + md.runtimeFunctionIndex = runtimeFunctionIndices.at(cmm.compiledFunctionIndex); + } + QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); QV4::Compiler::JSUnitGenerator jsUnitGenerator(&jsModule); QScopedPointer<QQmlJS::EvalInstructionSelection> isel(v4->iselFactory->create(v4->executableAllocator, &jsModule, &jsUnitGenerator)); @@ -3234,24 +3242,8 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod // Dynamic slot data - comes after the property data for (Object::DynamicSlot *s = obj->dynamicSlots.first(); s; s = obj->dynamicSlots.next(s)) { - int paramCount = s->parameterNames.count(); - - QString funcScript; - int namesSize = 0; - if (paramCount) namesSize += s->parameterNamesLength() + (paramCount - 1 /* commas */); - funcScript.reserve(strlen("(function ") + s->name.length() + 1 /* lparen */ + - namesSize + 1 /* rparen */ + s->body.length() + 1 /* rparen */); - funcScript = QLatin1String("(function ") + s->name.toString() + QLatin1Char('('); - for (int jj = 0; jj < paramCount; ++jj) { - if (jj) funcScript.append(QLatin1Char(',')); - funcScript.append(QLatin1String(s->parameterNames.at(jj))); - } - funcScript += QLatin1Char(')') + s->body + QLatin1Char(')'); - - QByteArray utf8 = funcScript.toUtf8(); - VMD::MethodData methodData = { s->parameterNames.count(), - dynamicData.size(), - utf8.length(), + VMD::MethodData methodData = { /*runtimeFunctionIndex*/ 0, // To be filled in later + s->parameterNames.count(), s->location.start.line }; VMD *vmd = (QQmlVMEMetaData *)dynamicData.data(); @@ -3259,7 +3251,12 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod vmd->methodCount++; md = methodData; - dynamicData.append((const char *)utf8.constData(), utf8.length()); + CompiledMetaMethod cmm; + cmm.obj = obj; + cmm.methodIndex = vmd->methodCount - 1; + functionsToCompile.append(s->funcDecl); + cmm.compiledFunctionIndex = functionsToCompile.count() - 1; + compiledMetaMethods.append(cmm); } if (aliasCount) |