Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimize QDeclarativePropertyCache
The creation of QDeclarativePropertyCaches contributes significantly
to the initial compile time of a QML app.

Change-Id: Iac5d1578155dfa4678a0e21eab51f4c1675762a9
Reviewed-on: http://codereview.qt.nokia.com/1026
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Jul 4, 2011
1 parent 8371e37 commit 71114ff
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 146 deletions.
10 changes: 5 additions & 5 deletions src/declarative/qml/qdeclarativecompiler.cpp
Expand Up @@ -981,7 +981,8 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj)
reinterpret_cast<const QDeclarativeVMEMetaData *>(obj->synthdata.constData());
for (int ii = 0; ii < vmeMetaData->aliasCount; ++ii) {
int index = obj->metaObject()->propertyOffset() + vmeMetaData->propertyCount + ii;
propertyCache->property(index)->flags |= QDeclarativePropertyCache::Data::IsAlias;
QDeclarativePropertyCache::Data *data = propertyCache->property(index);
data->setFlags(data->getFlags() | QDeclarativePropertyCache::Data::IsAlias);
}
}

Expand Down Expand Up @@ -1546,8 +1547,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
output->types.at(prop->parent->type).component) {

QDeclarativePropertyCache *cache = output->types.at(prop->parent->type).component->rootPropertyCache;
if (cache && cache->property(prop->index) &&
cache->property(prop->index)->flags & QDeclarativePropertyCache::Data::IsAlias)
if (cache && cache->property(prop->index) && cache->property(prop->index)->isAlias())
prop->isAlias = true;
}

Expand Down Expand Up @@ -3138,7 +3138,7 @@ int QDeclarativeCompiler::indexOfSignal(QDeclarativeParser::Object *object, cons
QDeclarativePropertyCache::Data *d = cache->property(strName);
if (notInRevision) *notInRevision = false;

while (d && !(d->flags & QDeclarativePropertyCache::Data::IsFunction))
while (d && !(d->isFunction()))
d = cache->overrideData(d);

if (d && !cache->isAllowedInRevision(d)) {
Expand Down Expand Up @@ -3178,7 +3178,7 @@ int QDeclarativeCompiler::indexOfProperty(QDeclarativeParser::Object *object, co

QDeclarativePropertyCache::Data *d = cache->property(strName);
// Find the first property
while (d && d->flags & QDeclarativePropertyCache::Data::IsFunction)
while (d && d->isFunction())
d = cache->overrideData(d);

if (d && !cache->isAllowedInRevision(d)) {
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativeenginedebug.cpp
Expand Up @@ -678,7 +678,7 @@ void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &m
QDeclarativePropertyCache::Data *prop =
QDeclarativePropertyCache::property(context->engine(), object, method, dummy);

if (!prop || !(prop->flags & QDeclarativePropertyCache::Data::IsVMEFunction))
if (!prop || !prop->isVMEFunction())
return;

QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativelist.cpp
Expand Up @@ -139,7 +139,7 @@ QDeclarativeListReference::QDeclarativeListReference(QObject *object, const char
QDeclarativePropertyCache::Data *data =
QDeclarativePropertyCache::property(engine, object, QLatin1String(property), local);

if (!data || !(data->flags & QDeclarativePropertyCache::Data::IsQList)) return;
if (!data || !data->isQList()) return;

QDeclarativeEnginePrivate *p = engine?QDeclarativeEnginePrivate::get(engine):0;

Expand Down
44 changes: 22 additions & 22 deletions src/declarative/qml/qdeclarativeproperty.cpp
Expand Up @@ -255,7 +255,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativePropertyCache::property(engine, obj, pathName, local);

if (!property) return; // Not a property
if (property->flags & QDeclarativePropertyCache::Data::IsFunction)
if (property->isFunction())
return; // Not an object property

if (ii == (path.count() - 2) && QDeclarativeValueTypeFactory::isValueType(property->propType)) {
Expand All @@ -277,7 +277,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name

return;
} else {
if (!(property->flags & QDeclarativePropertyCache::Data::IsQObjectDerived))
if (!property->isQObject())
return; // Not an object property

void *args[] = { &currentObject, 0 };
Expand Down Expand Up @@ -311,7 +311,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativePropertyCache::Data local;
QDeclarativePropertyCache::Data *property =
QDeclarativePropertyCache::property(engine, currentObject, terminal, local);
if (property && !(property->flags & QDeclarativePropertyCache::Data::IsFunction)) {
if (property && !property->isFunction()) {
object = currentObject;
core = *property;
nameCache = terminal;
Expand Down Expand Up @@ -371,9 +371,9 @@ QDeclarativePropertyPrivate::propertyTypeCategory() const
return QDeclarativeProperty::InvalidCategory;
else if (QDeclarativeValueTypeFactory::isValueType((uint)type))
return QDeclarativeProperty::Normal;
else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived)
else if (core.isQObject())
return QDeclarativeProperty::Object;
else if (core.flags & QDeclarativePropertyCache::Data::IsQList)
else if (core.isQList())
return QDeclarativeProperty::List;
else
return QDeclarativeProperty::Normal;
Expand Down Expand Up @@ -457,7 +457,7 @@ int QDeclarativePropertyPrivate::propertyType() const

QDeclarativeProperty::Type QDeclarativePropertyPrivate::type() const
{
if (core.flags & QDeclarativePropertyCache::Data::IsFunction)
if (core.isFunction())
return QDeclarativeProperty::SignalProperty;
else if (core.isValid())
return QDeclarativeProperty::Property;
Expand Down Expand Up @@ -520,12 +520,12 @@ bool QDeclarativeProperty::isWritable() const
return false;
if (!d->object)
return false;
if (d->core.flags & QDeclarativePropertyCache::Data::IsQList) //list
if (d->core.isQList()) //list
return true;
else if (d->core.flags & QDeclarativePropertyCache::Data::IsFunction) //signal handler
else if (d->core.isFunction()) //signal handler
return false;
else if (d->core.isValid()) //normal property
return d->core.flags & QDeclarativePropertyCache::Data::IsWritable;
else if (d->core.isValid()) //normal property
return d->core.isWritable();
else
return false;
}
Expand All @@ -551,7 +551,7 @@ bool QDeclarativeProperty::isResettable() const
if (!d)
return false;
if (type() & Property && d->core.isValid() && d->object)
return d->core.flags & QDeclarativePropertyCache::Data::IsResettable;
return d->core.isResettable();
else
return false;
}
Expand Down Expand Up @@ -682,7 +682,7 @@ QDeclarativePropertyPrivate::binding(QObject *object, int coreIndex, int valueTy

QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));

Expand Down Expand Up @@ -723,7 +723,7 @@ void QDeclarativePropertyPrivate::findAliasTarget(QObject *object, int bindingIn
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));
QObject *aObject = 0; int aCoreIndex = -1; int aValueTypeIndex = -1;
Expand Down Expand Up @@ -757,7 +757,7 @@ QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valu
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));

Expand Down Expand Up @@ -811,7 +811,7 @@ QDeclarativePropertyPrivate::setBindingNoEnable(QObject *object, int coreIndex,
if (data) {
QDeclarativePropertyCache::Data *propertyData =
data->propertyCache?data->propertyCache->property(coreIndex):0;
if (propertyData && propertyData->flags & QDeclarativePropertyCache::Data::IsAlias) {
if (propertyData && propertyData->isAlias()) {
const QDeclarativeVMEMetaObject *vme =
static_cast<const QDeclarativeVMEMetaObject *>(metaObjectForProperty(object->metaObject(), coreIndex));

Expand Down Expand Up @@ -994,14 +994,14 @@ QVariant QDeclarativePropertyPrivate::readValueProperty()
if (!ep) delete valueType;
return rv;

} else if (core.flags & QDeclarativePropertyCache::Data::IsQList) {
} else if (core.isQList()) {

QDeclarativeListProperty<QObject> prop;
void *args[] = { &prop, 0 };
QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args);
return QVariant::fromValue(QDeclarativeListReferencePrivate::init(prop, core.propType, engine));

} else if (core.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
} else if (core.isQObject()) {

QObject *rv = 0;
void *args[] = { &rv, 0 };
Expand Down Expand Up @@ -1077,7 +1077,7 @@ bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, Writ
writeBack->read(object, core.coreIndex);

QDeclarativePropertyCache::Data data = core;
data.flags = valueType.flags;
data.setFlags(valueType.flags);
data.coreIndex = valueType.valueTypeCoreIdx;
data.propType = valueType.valueTypePropType;
rv = write(writeBack, data, value, context, flags);
Expand All @@ -1101,7 +1101,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
int coreIdx = property.coreIndex;
int status = -1; //for dbus

if (property.flags & QDeclarativePropertyCache::Data::IsEnumType) {
if (property.isEnum()) {
QMetaProperty prop = object->metaObject()->property(property.coreIndex);
QVariant v = value;
// Enum values come through the script engine as doubles
Expand Down Expand Up @@ -1153,7 +1153,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
void *a[] = { (void *)&value, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);

} else if (property.flags & QDeclarativePropertyCache::Data::IsQObjectDerived) {
} else if (property.isQObject()) {

const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType());

Expand All @@ -1180,7 +1180,7 @@ bool QDeclarativePropertyPrivate::write(QObject *object, const QDeclarativePrope
return false;
}

} else if (property.flags & QDeclarativePropertyCache::Data::IsQList) {
} else if (property.isQList()) {

const QMetaObject *listType = 0;
if (enginePriv) {
Expand Down Expand Up @@ -1703,7 +1703,7 @@ static inline void flush_vme_signal(const QObject *object, int index)
if (data && data->propertyCache) {
QDeclarativePropertyCache::Data *property = data->propertyCache->method(index);

if (property && property->flags & QDeclarativePropertyCache::Data::IsVMESignal) {
if (property && property->isVMESignal()) {
const QMetaObject *metaObject = object->metaObject();
int methodOffset = metaObject->methodOffset();

Expand Down

0 comments on commit 71114ff

Please sign in to comment.