Cleanup: Store lookup tables inside the CompilationUnit
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 16 Aug 2013 10:36:13 +0000 (12:36 +0200)
committerLars Knoll <lars.knoll@digia.com>
Fri, 16 Aug 2013 14:51:10 +0000 (16:51 +0200)
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>
src/qml/compiler/qv4compileddata_p.h
src/qml/compiler/qv4compiler.cpp

index 0c5bf15..7b27d08 100644 (file)
@@ -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
index 7f2f611..385f668 100644 (file)
@@ -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