diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-04 14:43:10 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-05 16:31:45 +0200 |
commit | e203418096e66f2173d05788e5cb18e79141e772 (patch) | |
tree | a686a081985b9c120d83f6399af8b65fc7669aaa /src/qml/compiler | |
parent | 2024df6604dbb78f5eee6f61e73fb0d2fc3bb008 (diff) |
Reduce the size of Property fields in type compilation data
We can shave off 4 bytes of each property declaration by sharing the
bits for the custom type name index or the builtin type enum.
Change-Id: I77071cbef66c5a83b3e7e281dba3a435d3c68b39
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 25 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 31 |
2 files changed, 33 insertions, 23 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 8bdbab3b5a..6c61473418 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -872,13 +872,15 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) } else { const QStringRef &name = node->name; + Property *property = New<Property>(); + property->isReadOnly = node->isReadonlyMember; + bool typeFound = false; - QV4::CompiledData::Property::Type type = QV4::CompiledData::Property::Var; for (int ii = 0; !typeFound && ii < propTypeNameToTypesCount; ++ii) { const TypeNameToType *t = propTypeNameToTypes + ii; if (memberType == QLatin1String(t->name, static_cast<int>(t->nameLength))) { - type = t->type; + property->setBuiltinType(t->type); typeFound = true; } } @@ -886,11 +888,10 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) if (!typeFound && memberType.at(0).isUpper()) { const QStringRef &typeModifier = node->typeModifier; - if (typeModifier.isEmpty()) { - type = QV4::CompiledData::Property::Custom; - } else if (typeModifier == QLatin1String("list")) { - type = QV4::CompiledData::Property::CustomList; - } else { + property->setCustomType(registerString(memberType)); + if (typeModifier == QLatin1String("list")) { + property->isList = true; + } else if (!typeModifier.isEmpty()) { recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Invalid property type modifier")); return false; } @@ -905,14 +906,6 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) return false; } - Property *property = New<Property>(); - property->isReadOnly = node->isReadonlyMember; - property->type = type; - if (type >= QV4::CompiledData::Property::Custom) - property->customTypeNameIndex = registerString(memberType); - else - property->customTypeNameIndex = emptyStringIndex; - const QString propName = name.toString(); property->nameIndex = registerString(propName); @@ -1530,7 +1523,7 @@ bool IRBuilder::isStatementNodeScript(QQmlJS::AST::Statement *statement) bool IRBuilder::isRedundantNullInitializerForPropertyDeclaration(Property *property, QQmlJS::AST::Statement *statement) { - if (property->type != QV4::CompiledData::Property::Custom) + if (property->isBuiltinType || property->isList) return false; QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement); if (!exprStmt) diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 9123f9f0ec..639595509a 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -642,18 +642,35 @@ struct Property { enum Type : unsigned int { Var = 0, Variant, Int, Bool, Real, String, Url, Color, Font, Time, Date, DateTime, Rect, Point, Size, - Vector2D, Vector3D, Vector4D, Matrix4x4, Quaternion, - Custom, CustomList }; + Vector2D, Vector3D, Vector4D, Matrix4x4, Quaternion, InvalidBuiltin }; quint32_le nameIndex; union { - quint32_le_bitfield<0, 31> type; + quint32_le_bitfield<0, 29> builtinTypeOrTypeNameIndex; + quint32_le_bitfield<29, 1> isBuiltinType; + quint32_le_bitfield<30, 1> isList; quint32_le_bitfield<31, 1> isReadOnly; }; - quint32_le customTypeNameIndex; // If type >= Custom + Location location; + + void setBuiltinType(Type t) + { + builtinTypeOrTypeNameIndex = t; + isBuiltinType = true; + } + Type builtinType() const { + if (isBuiltinType) + return static_cast<Type>(quint32(builtinTypeOrTypeNameIndex)); + return InvalidBuiltin; + } + void setCustomType(int nameIndex) + { + builtinTypeOrTypeNameIndex = nameIndex; + isBuiltinType = false; + } }; -static_assert(sizeof(Property) == 16, "Property 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(Property) == 12, "Property structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); struct Alias { enum Flags : unsigned int { @@ -1044,8 +1061,8 @@ struct TypeReferenceMap : QHash<int, TypeReference> auto prop = obj->propertiesBegin(); auto propEnd = obj->propertiesEnd(); for ( ; prop != propEnd; ++prop) { - if (prop->type >= QV4::CompiledData::Property::Custom) { - TypeReference &r = this->add(prop->customTypeNameIndex, prop->location); + if (!prop->isBuiltinType) { + TypeReference &r = this->add(prop->builtinTypeOrTypeNameIndex, prop->location); r.errorWhenNotFound = true; } } |