aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-08-16 12:36:13 +0200
committerLars Knoll <lars.knoll@digia.com>2013-08-16 16:51:10 +0200
commit85e6b8e9e7e158b5cb4238c2dd5e28406bc913e2 (patch)
tree60607ebe1834a8378375421e946d62fe0e90c1ea /src/qml/compiler
parentd017fe9b38c74d2cc2fa754af3bf9e32357f149c (diff)
Cleanup: Store lookup tables inside the CompilationUnit
The size of each lookup is fixed, so it's easier to include in the unit itself. Change-Id: I66135efe4056eb0b4d7ff312eaa347fe98d8887f Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r--src/qml/compiler/qv4compileddata_p.h36
-rw-r--r--src/qml/compiler/qv4compiler.cpp10
2 files changed, 25 insertions, 21 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index 0c5bf15c02..7b27d08405 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -80,6 +80,20 @@ struct RegExp
static int calculateSize() { return sizeof(RegExp); }
};
+struct Lookup
+{
+ enum Type {
+ Type_Getter = 0x0,
+ Type_Setter = 0x1,
+ Type_GlobalGetter = 2
+ };
+
+ quint32 type_and_flags;
+ quint32 nameIndex;
+
+ static int calculateSize() { return sizeof(Lookup); }
+};
+
static const char magic_str[] = "qv4cdata";
struct Unit
@@ -121,7 +135,13 @@ struct Unit
return reinterpret_cast<const RegExp*>(reinterpret_cast<const char *>(this) + offsetToRegexpTable + index * sizeof(RegExp));
}
- static int calculateSize(uint nStrings, uint nFunctions, uint nRegExps) { return (sizeof(Unit) + (nStrings + nFunctions ) * sizeof(uint) + nRegExps * RegExp::calculateSize() + 7) & ~7; }
+ static int calculateSize(uint nStrings, uint nFunctions, uint nRegExps,
+ uint nLookups) {
+ return (sizeof(Unit)
+ + (nStrings + nFunctions) * sizeof(uint)
+ + nRegExps * RegExp::calculateSize()
+ + nLookups * Lookup::calculateSize()
+ + 7) & ~7; }
};
struct Function
@@ -176,20 +196,6 @@ struct String
}
};
-struct Lookup
-{
- enum Type {
- Type_Getter = 0x0,
- Type_Setter = 0x1,
- Type_GlobalGetter = 2
- };
-
- quint32 type_and_flags;
- quint32 nameIndex;
-
- static int calculateSize() { return sizeof(Lookup); }
-};
-
// Qml data structures
struct Value
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index 7f2f611898..385f668b42 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -127,7 +127,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
registerString(*f->locals.at(i));
}
- int unitSize = QV4::CompiledData::Unit::calculateSize(strings.size(), irModule->functions.size(), regexps.size());
+ int unitSize = QV4::CompiledData::Unit::calculateSize(strings.size(), irModule->functions.size(), regexps.size(), lookups.size());
uint functionDataSize = 0;
for (int i = 0; i < irModule->functions.size(); ++i) {
@@ -142,9 +142,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
functionDataSize += QV4::CompiledData::Function::calculateSize(f->formals.size(), f->locals.size(), f->nestedFunctions.size(), lineNumberMappingCount);
}
- const uint lookupDataSize = CompiledData::Lookup::calculateSize() * lookups.count();
-
- char *data = (char *)malloc(unitSize + functionDataSize + stringDataSize + lookupDataSize);
+ char *data = (char *)malloc(unitSize + functionDataSize + stringDataSize);
QV4::CompiledData::Unit *unit = (QV4::CompiledData::Unit*)data;
memcpy(unit->magic, QV4::CompiledData::magic_str, sizeof(unit->magic));
@@ -156,9 +154,9 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
unit->functionTableSize = irModule->functions.size();
unit->offsetToFunctionTable = unit->offsetToStringTable + unit->stringTableSize * sizeof(uint);
unit->lookupTableSize = lookups.count();
+ unit->offsetToLookupTable = unit->offsetToFunctionTable + unit->functionTableSize * sizeof(uint);
unit->regexpTableSize = regexps.size();
- unit->offsetToRegexpTable = unit->offsetToFunctionTable + unit->functionTableSize * sizeof(uint);
- unit->offsetToLookupTable = unitSize + stringDataSize + functionDataSize;
+ unit->offsetToRegexpTable = unit->offsetToLookupTable + unit->lookupTableSize * CompiledData::Lookup::calculateSize();
unit->sourceFileIndex = getStringId(irModule->fileName);
// write strings and string table