diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-10-27 22:32:19 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 14:06:06 +0100 |
commit | 9880e64efa25c1924b95068693ff8664e2f2e121 (patch) | |
tree | d9b577e90e1383645bc796d298d6781be204fe2d /src/qml/compiler/qv4compiler.cpp | |
parent | 9b18946f22b8fc15a1223378112a53b2089380cf (diff) |
Add a constant table to the compiled data
This will help simplifying and speeding up the moth generated
code.
Change-Id: I1b87c4b25dbfa6ce2e8a0b77e526f7fc063b0de2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 7d8c188927..2d14c0f69a 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -115,6 +115,15 @@ int QV4::Compiler::JSUnitGenerator::registerRegExp(QQmlJS::V4IR::RegExp *regexp) return regexps.size() - 1; } +int QV4::Compiler::JSUnitGenerator::registerConstant(QV4::ReturnedValue v) +{ + int idx = constants.indexOf(v); + if (idx >= 0) + return idx; + constants.append(v); + return constants.size() - 1; +} + void QV4::Compiler::JSUnitGenerator::registerLineNumberMapping(QQmlJS::V4IR::Function *function, const QVector<uint> &mappings) { lineNumberMappingsPerFunction.insert(function, mappings); @@ -162,7 +171,8 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total registerString(*f->locals.at(i)); } - int unitSize = QV4::CompiledData::Unit::calculateSize(headerSize, strings.size(), irModule->functions.size(), regexps.size(), lookups.size(), jsClasses.count()); + int unitSize = QV4::CompiledData::Unit::calculateSize(headerSize, strings.size(), irModule->functions.size(), regexps.size(), + constants.size(), lookups.size(), jsClasses.count()); uint functionDataSize = 0; for (int i = 0; i < irModule->functions.size(); ++i) { @@ -196,8 +206,10 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total unit->offsetToLookupTable = unit->offsetToFunctionTable + unit->functionTableSize * sizeof(uint); unit->regexpTableSize = regexps.size(); unit->offsetToRegexpTable = unit->offsetToLookupTable + unit->lookupTableSize * CompiledData::Lookup::calculateSize(); + unit->constantTableSize = constants.size(); + unit->offsetToConstantTable = unit->offsetToRegexpTable + unit->regexpTableSize * CompiledData::RegExp::calculateSize(); unit->jsClassTableSize = jsClasses.count(); - unit->offsetToJSClassTable = unit->offsetToRegexpTable + unit->regexpTableSize * CompiledData::RegExp::calculateSize(); + unit->offsetToJSClassTable = unit->offsetToConstantTable + unit->constantTableSize * sizeof(ReturnedValue); unit->indexOfRootFunction = -1; unit->sourceFileIndex = getStringId(irModule->fileName); @@ -242,6 +254,9 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total CompiledData::RegExp *regexpTable = (CompiledData::RegExp *)(data + unit->offsetToRegexpTable); memcpy(regexpTable, regexps.constData(), regexps.size() * sizeof(*regexpTable)); + ReturnedValue *constantTable = (ReturnedValue *)(data + unit->offsetToConstantTable); + memcpy(constantTable, constants.constData(), constants.size() * sizeof(ReturnedValue)); + // write js classes and js class lookup table uint *jsClassTable = (uint*)(data + unit->offsetToJSClassTable); char *jsClass = data + unitSize + stringDataSize + functionDataSize; |