diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-28 04:43:56 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-28 04:43:56 (GMT) |
commit | 2489ac6515d6ae5a403974e151b9a6cba4a3ea3f (patch) | |
tree | 5cb78801206cd893d74563c5bb1e8b03cf865214 /src/declarative/qml | |
parent | 57a76a94e5b60c5c7c82ec86bea4f206f6f08f4e (diff) | |
download | Qt-2489ac6515d6ae5a403974e151b9a6cba4a3ea3f.zip Qt-2489ac6515d6ae5a403974e151b9a6cba4a3ea3f.tar.gz Qt-2489ac6515d6ae5a403974e151b9a6cba4a3ea3f.tar.bz2 |
Don't unnecessarily regenerate property cache
Improves compilation:boomblock benchmark by 22%
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 17 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine_p.h | 56 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativepropertycache.cpp | 29 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativepropertycache_p.h | 1 |
4 files changed, 75 insertions, 28 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 1727687..59a0d4d 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -938,19 +938,28 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj) meta.storeMeta.propertyCache = output->propertyCaches.count(); // ### Surely the creation of this property cache could be more efficient QDeclarativePropertyCache *propertyCache = 0; - if (tr.component && QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache) { + if (tr.component) propertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache->copy(); - } else { - propertyCache = QDeclarativePropertyCache::create(engine, obj->metaObject()->superClass()); - } + else + propertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()->superClass())->copy(); + propertyCache->append(engine, obj->metaObject(), QDeclarativePropertyCache::Data::NoFlags, QDeclarativePropertyCache::Data::IsVMEFunction); + if (obj == unitRoot) { propertyCache->addref(); output->rootPropertyCache = propertyCache; } + output->propertyCaches << propertyCache; output->bytecode << meta; + } else if (obj == unitRoot) { + if (tr.component) + output->rootPropertyCache = QDeclarativeComponentPrivate::get(tr.component)->cc->rootPropertyCache; + else + output->rootPropertyCache = QDeclarativeEnginePrivate::get(engine)->cache(obj->metaObject()); + + output->rootPropertyCache->addref(); } // Set the object id diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 743275e..ca033bf 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -244,18 +244,8 @@ public: QDeclarativeValueTypeFactory valueTypes; QHash<const QMetaObject *, QDeclarativePropertyCache *> propertyCache; - QDeclarativePropertyCache *cache(QObject *obj) { - Q_Q(QDeclarativeEngine); - if (!obj || QObjectPrivate::get(obj)->metaObject || - QObjectPrivate::get(obj)->wasDeleted) return 0; - const QMetaObject *mo = obj->metaObject(); - QDeclarativePropertyCache *rv = propertyCache.value(mo); - if (!rv) { - rv = QDeclarativePropertyCache::create(q, mo); - propertyCache.insert(mo, rv); - } - return rv; - } + inline QDeclarativePropertyCache *cache(QObject *obj); + inline QDeclarativePropertyCache *cache(const QMetaObject *); // ### This whole class is embarrassing struct Imports { @@ -361,6 +351,48 @@ public: static void defineModule(); }; +/*! +Returns a QDeclarativePropertyCache for \a obj if one is available. + +If \a obj is null, being deleted or contains a dynamic meta object 0 +is returned. +*/ +QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(QObject *obj) +{ + Q_Q(QDeclarativeEngine); + if (!obj || QObjectPrivate::get(obj)->metaObject || QObjectPrivate::get(obj)->wasDeleted) + return 0; + + const QMetaObject *mo = obj->metaObject(); + QDeclarativePropertyCache *rv = propertyCache.value(mo); + if (!rv) { + rv = new QDeclarativePropertyCache(q, mo); + propertyCache.insert(mo, rv); + } + return rv; +} + +/*! +Returns a QDeclarativePropertyCache for \a metaObject. + +As the cache is persisted for the life of the engine, \a metaObject must be +a static "compile time" meta-object, or a meta-object that is otherwise known to +exist for the lifetime of the QDeclarativeEngine. +*/ +QDeclarativePropertyCache *QDeclarativeEnginePrivate::cache(const QMetaObject *metaObject) +{ + Q_Q(QDeclarativeEngine); + Q_ASSERT(metaObject); + + QDeclarativePropertyCache *rv = propertyCache.value(metaObject); + if (!rv) { + rv = new QDeclarativePropertyCache(q, metaObject); + propertyCache.insert(metaObject, rv); + } + + return rv; +} + QT_END_NAMESPACE #endif // QDECLARATIVEENGINE_P_H diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 888945b..f04a706 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -106,9 +106,25 @@ void QDeclarativePropertyCache::Data::load(const QMetaMethod &m) } +/*! +Creates a new empty QDeclarativePropertyCache. +*/ QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e) : QDeclarativeCleanup(e), engine(e) { + Q_ASSERT(engine); +} + +/*! +Creates a new QDeclarativePropertyCache of \a metaObject. +*/ +QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e, const QMetaObject *metaObject) +: QDeclarativeCleanup(e), engine(e) +{ + Q_ASSERT(engine); + Q_ASSERT(metaObject); + + update(engine, metaObject); } QDeclarativePropertyCache::~QDeclarativePropertyCache() @@ -135,7 +151,7 @@ void QDeclarativePropertyCache::clear() } QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObject *metaObject, - const QString &property) + const QString &property) { Q_ASSERT(metaObject); @@ -245,17 +261,6 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb } } -// ### Optimize - check engine for the parent meta object etc. -QDeclarativePropertyCache *QDeclarativePropertyCache::create(QDeclarativeEngine *engine, const QMetaObject *metaObject) -{ - Q_ASSERT(engine); - Q_ASSERT(metaObject); - - QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine); - cache->update(engine, metaObject); - return cache; -} - void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject) { Q_ASSERT(engine); diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h index 6b64a96..b01e5cc 100644 --- a/src/declarative/qml/qdeclarativepropertycache_p.h +++ b/src/declarative/qml/qdeclarativepropertycache_p.h @@ -69,6 +69,7 @@ class QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarati { public: QDeclarativePropertyCache(QDeclarativeEngine *); + QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *); virtual ~QDeclarativePropertyCache(); struct Data { |