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:
parent
1f1a322373
commit
a9ba5fe7aa
@ -1031,8 +1031,8 @@ int QMetaObject::indexOfProperty(const char *name) const
|
|||||||
while (m) {
|
while (m) {
|
||||||
const QMetaObjectPrivate *d = priv(m->d.data);
|
const QMetaObjectPrivate *d = priv(m->d.data);
|
||||||
for (int i = 0; i < d->propertyCount; ++i) {
|
for (int i = 0; i < d->propertyCount; ++i) {
|
||||||
const QMetaProperty p(m, i);
|
const QMetaProperty::Data data = QMetaProperty::getMetaPropertyData(m, i);
|
||||||
const char *prop = rawStringData(m, p.data.name());
|
const char *prop = rawStringData(m, data.name());
|
||||||
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
|
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
|
||||||
i += m->propertyOffset();
|
i += m->propertyOffset();
|
||||||
return i;
|
return i;
|
||||||
@ -3104,7 +3104,7 @@ int QMetaProperty::registerPropertyType() const
|
|||||||
|
|
||||||
QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index)
|
QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index)
|
||||||
: mobj(mobj),
|
: 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);
|
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
|
Returns the enumerator if this property's type is an enumerator
|
||||||
type; otherwise the returned value is undefined.
|
type; otherwise the returned value is undefined.
|
||||||
|
@ -348,6 +348,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QMetaProperty(const QMetaObject *mobj, int index);
|
QMetaProperty(const QMetaObject *mobj, int index);
|
||||||
|
static Data getMetaPropertyData(const QMetaObject *mobj, int index);
|
||||||
|
|
||||||
const QMetaObject *mobj;
|
const QMetaObject *mobj;
|
||||||
Data data;
|
Data data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user