diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-20 15:54:53 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-31 07:28:52 +0000 |
commit | 41076956f7d38d9c661ae97111af9834786efa24 (patch) | |
tree | cb196b4b7e628991a021784a41d9e82af3c3222f | |
parent | 2ee5331d8ae73c0abde129eb26df4ca000470007 (diff) |
Shrink CompiledData::Function by 8 bytes
We can express the offset to the line number table relative
to the locals.
Saves ~1.4k with examples/quickcontrols/extras/flat/Content.qml and ~11K
RAM with the gallery.
Task-number: QTBUG-69588
Change-Id: I802928102b4291e05ff1462226d22303f8a6d35b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 13 | ||||
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 4 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 20e8db528e..715882c985 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -263,18 +263,17 @@ struct Function quint32_le nameIndex; quint16_le length; quint16_le nFormals; - quint32_le formalsOffset; + quint32_le formalsOffset; // Can't turn this into a calculated offset because of the mutation in CompilationUnit::createUnitData. quint32_le localsOffset; quint16_le nLocals; quint16_le nLineNumbers; - quint32_le lineNumberOffset; + size_t lineNumberOffset() const { return localsOffset + nLocals * sizeof(quint32); } quint32_le nestedFunctionIndex; // for functions that only return a single closure, used in signal handlers - quint32_le nRegisters; Location location; // Qml Extensions Begin // Array of resolved ID objects - size_t dependingIdObjectsOffset() const { return lineNumberOffset + nLineNumbers * sizeof(CodeOffsetToLine); } + size_t dependingIdObjectsOffset() const { return lineNumberOffset() + nLineNumbers * sizeof(CodeOffsetToLine); } quint16_le nDependingIdObjects; quint16_le nDependingContextProperties; // Array of int pairs (property index and notify index) @@ -287,14 +286,14 @@ struct Function // Keep all unaligned data at the end quint8 flags; quint8 padding1; - quint16_le padding2; + quint16_le nRegisters; // quint32 formalsIndex[nFormals] // quint32 localsIndex[nLocals] const quint32_le *formalsTable() const { return reinterpret_cast<const quint32_le *>(reinterpret_cast<const char *>(this) + formalsOffset); } const quint32_le *localsTable() const { return reinterpret_cast<const quint32_le *>(reinterpret_cast<const char *>(this) + localsOffset); } - const CodeOffsetToLine *lineNumberTable() const { return reinterpret_cast<const CodeOffsetToLine *>(reinterpret_cast<const char *>(this) + lineNumberOffset); } + const CodeOffsetToLine *lineNumberTable() const { return reinterpret_cast<const CodeOffsetToLine *>(reinterpret_cast<const char *>(this) + lineNumberOffset()); } const quint32_le *qmlIdObjectDependencyTable() const { return reinterpret_cast<const quint32_le *>(reinterpret_cast<const char *>(this) + dependingIdObjectsOffset()); } const quint32_le *qmlContextPropertiesDependencyTable() const { return reinterpret_cast<const quint32_le *>(reinterpret_cast<const char *>(this) + dependingContextPropertiesOffset()); } const quint32_le *qmlScopePropertiesDependencyTable() const { return reinterpret_cast<const quint32_le *>(reinterpret_cast<const char *>(this) + dependingScopePropertiesOffset()); } @@ -320,7 +319,7 @@ struct Function return (a + 7) & ~size_t(7); } }; -static_assert(sizeof(Function) == 56, "Function structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); +static_assert(sizeof(Function) == 48, "Function structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); struct Method { enum Type { diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 252056b2b6..6dbd4a35fb 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -331,7 +331,7 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte currentOffset += function->nLocals * sizeof(quint32); function->nLineNumbers = irFunction->lineNumberMapping.size(); - function->lineNumberOffset = currentOffset; + Q_ASSERT(function->lineNumberOffset() == currentOffset); currentOffset += function->nLineNumbers * sizeof(CompiledData::CodeOffsetToLine); @@ -376,7 +376,7 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte locals[i] = getStringId(irFunction->locals.at(i)); // write line numbers - memcpy(f + function->lineNumberOffset, irFunction->lineNumberMapping.constData(), irFunction->lineNumberMapping.size()*sizeof(CompiledData::CodeOffsetToLine)); + memcpy(f + function->lineNumberOffset(), irFunction->lineNumberMapping.constData(), irFunction->lineNumberMapping.size()*sizeof(CompiledData::CodeOffsetToLine)); // write QML dependencies quint32_le *writtenDeps = (quint32_le *)(f + function->dependingIdObjectsOffset()); |