summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlmetaproperty.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-08-06 04:10:50 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-08-06 04:10:50 (GMT)
commit28a8c6b02e52bce8b2ac14961997b9c2cc0e01fd (patch)
treeebbf92dbb7ba6aaffc9b505203431115ed0bba99 /src/declarative/qml/qmlmetaproperty.cpp
parentf132fde07d0d852f2aa61dbc80d5d5f89ae5dcfa (diff)
downloadQt-28a8c6b02e52bce8b2ac14961997b9c2cc0e01fd.zip
Qt-28a8c6b02e52bce8b2ac14961997b9c2cc0e01fd.tar.gz
Qt-28a8c6b02e52bce8b2ac14961997b9c2cc0e01fd.tar.bz2
Use meta property cache for property restores
Diffstat (limited to 'src/declarative/qml/qmlmetaproperty.cpp')
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp103
1 files changed, 69 insertions, 34 deletions
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 350d84b..c445599 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -56,25 +56,53 @@ Q_DECLARE_METATYPE(QList<QObject *>);
QT_BEGIN_NAMESPACE
-QmlMetaObjectCache::Data
-QmlMetaObjectCache::property(const QString &name, const QMetaObject *metaObject)
+QmlMetaObjectCache::QmlMetaObjectCache()
+: propertyCache(0)
{
- QHash<QString, Data>::ConstIterator iter = properties.find(name);
- if (iter != properties.end()) {
- return *iter;
- } else {
- Data cacheData = { -1, -1 };
+}
+
+void QmlMetaObjectCache::init(const QMetaObject *metaObject)
+{
+ if (propertyCache || !metaObject)
+ return;
+
+ int propCount = metaObject->propertyCount();
+
+ propertyCache = new Data[propCount];
+ for (int ii = 0; ii < propCount; ++ii) {
+ QMetaProperty p = metaObject->property(ii);
+ propertyCache[ii].propType = p.userType();
+ propertyCache[ii].coreIndex = ii;
+ propertyCache[ii].name = QLatin1String(p.name());
+
+ propertyNameCache.insert(propertyCache[ii].name, ii);
+ }
+}
+
+QmlMetaObjectCache::~QmlMetaObjectCache()
+{
+ delete [] propertyCache;
+}
+
+QmlMetaObjectCache::Data *
+QmlMetaObjectCache::property(int index, const QMetaObject *metaObject)
+{
+ init(metaObject);
- int idx = metaObject->indexOfProperty(name.toUtf8().constData());
- if (idx == -1)
- return cacheData;
+ return propertyCache + index;
+}
+
+QmlMetaObjectCache::Data *
+QmlMetaObjectCache::property(const QString &name, const QMetaObject *metaObject)
+{
+ init(metaObject);
- QMetaProperty property = metaObject->property(idx);
- cacheData.propType = property.userType();
- cacheData.coreIndex = idx;
- properties.insert(name, cacheData);
+ QHash<QString, int>::ConstIterator iter = propertyNameCache.find(name);
- return cacheData;
+ if (iter != propertyNameCache.end()) {
+ return propertyCache + *iter;
+ } else {
+ return 0;
}
}
@@ -99,14 +127,6 @@ QmlMetaProperty::~QmlMetaProperty()
delete d; d = 0;
}
-struct CachedPropertyData {
- CachedPropertyData(const QString &n, int pt, int ci)
- : name(n), propType(pt), coreIdx(ci) {}
- QString name;
- int propType;
- int coreIdx;
-};
-
/*!
Creates a QmlMetaProperty for the default property of \a obj. If there is no
default property, an invalid QmlMetaProperty will be created.
@@ -218,15 +238,14 @@ void QmlMetaPropertyPrivate::initProperty(QObject *obj, const QString &name)
}
// Property
- if (!QObjectPrivate::get(obj)->metaObject && enginePrivate) {
- // Can cache
- QmlMetaObjectCache &cache =
- enginePrivate->propertyCache[obj->metaObject()];
- QmlMetaObjectCache::Data data = cache.property(name, obj->metaObject());
- if (data.coreIndex != -1) {
+ QmlMetaObjectCache *cache = QmlEnginePrivate::cache(enginePrivate, obj);
+ if (cache) {
+ QmlMetaObjectCache::Data *data =
+ cache->property(name, obj->metaObject());
+ if (data) {
type = QmlMetaProperty::Property;
- propType = data.propType;
- coreIdx = data.coreIndex;
+ propType = data->propType;
+ coreIdx = data->coreIndex;
}
} else {
// Can't cache
@@ -1015,6 +1034,10 @@ quint32 QmlMetaPropertyPrivate::saveProperty(int core)
*/
void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
{
+ QmlEnginePrivate *enginePrivate = 0;
+ if (ctxt && ctxt->engine())
+ enginePrivate = QmlEnginePrivate::get(ctxt->engine());
+
d->object = obj;
d->context = ctxt;
@@ -1042,10 +1065,22 @@ void QmlMetaProperty::restore(quint32 id, QObject *obj, QmlContext *ctxt)
d->valueTypeId = p.type();
} else if (d->type & Property) {
- QMetaProperty p(obj->metaObject()->property(id));
- d->name = QLatin1String(p.name());
- d->propType = p.userType();
+
+ QmlMetaObjectCache *cache = QmlEnginePrivate::cache(enginePrivate, obj);
+
d->coreIdx = id;
+
+ if (cache) {
+ QmlMetaObjectCache::Data *data =
+ cache->property(id, obj->metaObject());
+ d->propType = data->propType;
+ d->name = data->name;
+ } else {
+ QMetaProperty p(obj->metaObject()->property(id));
+ d->name = QLatin1String(p.name());
+ d->propType = p.userType();
+ }
+
} else if (d->type & SignalProperty) {
d->signal = obj->metaObject()->method(id);
d->coreIdx = id;