diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2024-05-02 23:46:32 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2024-05-06 16:52:05 +0200 |
commit | 23f983fa09aa378129ed34de8ab4c2ec95d18ab9 (patch) | |
tree | 99bebef3b96e2271afb2355b3897e6902e59c91b /src | |
parent | fd54b88d394447315df325f25d5ece2c1f1ca292 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 148983f126..05662b385a 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)); |