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>
This commit is contained in:
Fabian Kosmale 2020-11-24 10:59:08 +01:00
parent 1f1a322373
commit a9ba5fe7aa
2 changed files with 13 additions and 3 deletions

View File

@ -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.

View File

@ -348,6 +348,7 @@ private:
};
QMetaProperty(const QMetaObject *mobj, int index);
static Data getMetaPropertyData(const QMetaObject *mobj, int index);
const QMetaObject *mobj;
Data data;