From a9ba5fe7aad1fd47828eec3202f8f91d1d8e55e2 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 24 Nov 2020 10:59:08 +0100 Subject: 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 Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetaobject.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/corelib/kernel/qmetaobject.cpp') 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); @@ -3141,6 +3141,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. -- cgit v1.2.3