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 <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Mårten Nordheim 2024-05-02 23:46:32 +02:00
parent fd54b88d39
commit 23f983fa09

View File

@ -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));