summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetaobject.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-11-24 10:59:08 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-12-01 09:12:09 +0100
commita9ba5fe7aad1fd47828eec3202f8f91d1d8e55e2 (patch)
tree75299cd2c22b3849b5fe45159db1ca61efcfebb1 /src/corelib/kernel/qmetaobject.cpp
parent1f1a3223734c42447ad527056dad47feeaf64b8f (diff)
QMetaProperty: Enable constructing only Data
Constructing a QMetaProperty can be unnecessarily expensive due to the QMetaEnum resolution. Add a private method to construct only QMetaProperty::Data. Make us of it in indexOfProperty. Task-number: QTBUG-82931 Change-Id: If954538106bcfaa7d088db26591f6bd6eeaf3731 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index bdd2af1a2e..650ea60617 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -1031,8 +1031,8 @@ int QMetaObject::indexOfProperty(const char *name) const
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
for (int i = 0; i < d->propertyCount; ++i) {
- const QMetaProperty p(m, i);
- const char *prop = rawStringData(m, p.data.name());
+ const QMetaProperty::Data data = QMetaProperty::getMetaPropertyData(m, i);
+ const char *prop = rawStringData(m, data.name());
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->propertyOffset();
return i;
@@ -3104,7 +3104,7 @@ int QMetaProperty::registerPropertyType() const
QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index)
: mobj(mobj),
- data({ mobj->d.data + priv(mobj->d.data)->propertyData + index * Data::Size })
+ data(getMetaPropertyData(mobj, index))
{
Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->propertyCount);
@@ -3142,6 +3142,15 @@ QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index)
}
/*!
+ \internal
+ Constructs the \c QMetaProperty::Data for the \a index th property of \a mobj
+ */
+QMetaProperty::Data QMetaProperty::getMetaPropertyData(const QMetaObject *mobj, int index)
+{
+ return { mobj->d.data + priv(mobj->d.data)->propertyData + index * Data::Size };
+}
+
+/*!
Returns the enumerator if this property's type is an enumerator
type; otherwise the returned value is undefined.