From 23f983fa09aa378129ed34de8ab4c2ec95d18ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 2 May 2024 23:46:32 +0200 Subject: QMetaProperty: limit QMetaEnum resolution to enums known to QMetaType Since we don't know ahead of time if a property's type is an enum or a flag we have to resolve it at runtime. In a QMetaProperty-heavy application this overhead can be quite dramatic given that we mark anything that is not a built-in as a potential flag/enum. However, QMetaType already knows if it's an enum, so we can use that to return early if it's not known to the meta-type system. To add to this - Q_PROPERTY requires that a type is fully defined, so there are no issues with forward declarations for the enums. Change-Id: Ifecc7f1e6cdef416e3ce72ee705eb26e682071cc Reviewed-by: Thiago Macieira Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetaobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/kernel/qmetaobject.cpp') diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 148983f1268..05662b385a5 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -3656,8 +3656,8 @@ QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index) data(getMetaPropertyData(mobj, index)) { Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->propertyCount); - - if (!(data.flags() & EnumOrFlag)) + // The code below here just resolves menum if the property is an enum type: + if (!(data.flags() & EnumOrFlag) || !metaType().flags().testFlag(QMetaType::IsEnumeration)) return; QByteArrayView enum_name = typeNameFromTypeInfo(mobj, data.type()); menum = mobj->enumerator(QMetaObjectPrivate::indexOfEnumerator(mobj, enum_name)); -- cgit v1.2.3