From 2642058df8429cd593d0c7adf45a818a42fc0d88 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 4 May 2022 11:47:38 +0200 Subject: QML: Port QV4::CompiledData::ParameterType to new special integer bitfield Pick-to: 5.15 6.2 6.3 Task-number: QTBUG-99545 Change-Id: I515aa7a605accc4b45f9dd4918dd6bfb6e116379 Reviewed-by: Fabian Kosmale Reviewed-by: Sami Shalayel --- src/qml/common/qv4compileddata_p.h | 25 ++++++++++++++++++++----- src/qml/compiler/qqmlirbuilder.cpp | 12 +++++------- src/qml/qml/qqmlpropertycachecreator_p.h | 7 ++++--- 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'src/qml') diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 297cee3610..0d2c171e5d 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -273,11 +273,26 @@ enum class BuiltinType : unsigned int { struct ParameterType { - union { - quint32 _dummy; - quint32_le_bitfield<0, 1> indexIsBuiltinType; - quint32_le_bitfield<1, 31> typeNameIndexOrBuiltinType; - }; + void set(bool indexIsBuiltinType, quint32 typeNameIndexOrBuiltinType) + { + m_data.set(indexIsBuiltinType ? 1 : 0); + m_data.set(typeNameIndexOrBuiltinType); + } + + bool indexIsBuiltinType() const + { + return m_data.get() != 0; + } + + quint32 typeNameIndexOrBuiltinType() const + { + return m_data.get(); + } + +private: + using IndexIsBuiltinTypeField = quint32_le_bitfield_member<0, 1>; + using TypeNameIndexOrBuiltinTypeField = quint32_le_bitfield_member<1, 31>; + quint32_le_bitfield_union m_data; }; static_assert(sizeof(ParameterType) == 4, "ParameterType structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index bd3e5e7bde..8a61a58486 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -108,20 +108,18 @@ bool Parameter::init(QV4::CompiledData::Parameter *param, const QV4::Compiler::J bool Parameter::initType(QV4::CompiledData::ParameterType *paramType, const QV4::Compiler::JSUnitGenerator *stringGenerator, int typeNameIndex) { - paramType->indexIsBuiltinType = false; - paramType->typeNameIndexOrBuiltinType = 0; const QString typeName = stringGenerator->stringForIndex(typeNameIndex); auto builtinType = stringToBuiltinType(typeName); if (builtinType == QV4::CompiledData::BuiltinType::InvalidBuiltin) { - if (typeName.isEmpty()) + if (typeName.isEmpty()) { + paramType->set(false, 0); return false; - paramType->indexIsBuiltinType = false; - paramType->typeNameIndexOrBuiltinType = typeNameIndex; + } Q_ASSERT(quint32(typeNameIndex) < (1u << 31)); + paramType->set(false, typeNameIndex); } else { - paramType->indexIsBuiltinType = true; - paramType->typeNameIndexOrBuiltinType = static_cast(builtinType); Q_ASSERT(quint32(builtinType) < (1u << 31)); + paramType->set(true, static_cast(builtinType)); } return true; } diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index f683dc208c..892b08c614 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -743,13 +743,14 @@ template inline QMetaType QQmlPropertyCacheCreator::metaTypeForParameter(const QV4::CompiledData::ParameterType ¶m, QString *customTypeName) { - if (param.indexIsBuiltinType) { + if (param.indexIsBuiltinType()) { // built-in type - return metaTypeForPropertyType(static_cast(int(param.typeNameIndexOrBuiltinType))); + return metaTypeForPropertyType( + static_cast(param.typeNameIndexOrBuiltinType())); } // lazily resolved type - const QString typeName = stringAt(param.typeNameIndexOrBuiltinType); + const QString typeName = stringAt(param.typeNameIndexOrBuiltinType()); if (customTypeName) *customTypeName = typeName; QQmlType qmltype; -- cgit v1.2.3