Skip to content

Commit

Permalink
VisualDataModel performance improvements.
Browse files Browse the repository at this point in the history
Avoid a linear scan of all cache items and associated accesses by
getting the cache item from an objects  vdm attached object instead.

Make the model context property a property of the context object instead
of a separate property on the context object.

Parent the vdm attached object to the delegate object with
QDeclarative_setParent_noEvent instead of passing it in the constructor.

Change-Id: Ib77c5cdb963f3dfe8f2bdef039e010a6bb30140f
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Dec 23, 2011
1 parent fb00bd4 commit ed36194
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
29 changes: 7 additions & 22 deletions src/quick/items/qquickvisualdatamodel.cpp
Expand Up @@ -418,9 +418,8 @@ QQuickVisualDataModel::ReleaseFlags QQuickVisualDataModelPrivate::release(QObjec
if (!object)
return stat;

int cacheIndex = cacheIndexOf(object);
if (cacheIndex != -1) {
QQuickVisualDataModelItem *cacheItem = m_cache.at(cacheIndex);
if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(object)) {
QQuickVisualDataModelItem *cacheItem = attached->m_cacheItem;
if (cacheItem->releaseObject()) {
destroy(object);
if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
Expand Down Expand Up @@ -782,7 +781,6 @@ QObject *QQuickVisualDataModelPrivate::object(Compositor::Group group, int index
}
}

ctxt->setContextProperty(QLatin1String("model"), cacheItem);
ctxt->setContextObject(cacheItem);

incubator->incubating = cacheItem;
Expand Down Expand Up @@ -844,22 +842,12 @@ QString QQuickVisualDataModel::stringValue(int index, const QString &name)
return d->stringValue(d->m_compositorGroup, index, name);
}

int QQuickVisualDataModelPrivate::cacheIndexOf(QObject *object) const
{
for (int cacheIndex = 0; cacheIndex < m_cache.count(); ++cacheIndex) {
if (m_cache.at(cacheIndex)->object == object)
return cacheIndex;
}
return -1;
}

int QQuickVisualDataModel::indexOf(QQuickItem *item, QObject *) const
{
Q_D(const QQuickVisualDataModel);
const int cacheIndex = d->cacheIndexOf(item);
return cacheIndex != -1
? d->m_cache.at(cacheIndex)->index[d->m_compositorGroup]
: -1;
if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(item))
return attached->m_cacheItem->index[d->m_compositorGroup];
return -1;
}

void QQuickVisualDataModel::setWatchedRoles(QList<QByteArray> roles)
Expand Down Expand Up @@ -2555,11 +2543,8 @@ int QQuickVisualPartsModel::indexOf(QQuickItem *item, QObject *) const
{
QHash<QObject *, QDeclarativePackage *>::const_iterator it = m_packaged.find(item);
if (it != m_packaged.end()) {
const QQuickVisualDataModelPrivate *model = QQuickVisualDataModelPrivate::get(m_model);
const int cacheIndex = model->cacheIndexOf(*it);
return cacheIndex != -1
? model->m_cache.at(cacheIndex)->index[m_compositorGroup]
: -1;
if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(*it))
return attached->m_cacheItem->index[m_compositorGroup];
}
return -1;
}
Expand Down
10 changes: 6 additions & 4 deletions src/quick/items/qquickvisualdatamodel_p.h
Expand Up @@ -46,11 +46,12 @@
#include <private/qdeclarativelistcompositor_p.h>
#include <private/qquickvisualitemmodel_p.h>


#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qstringlist.h>


#include <private/qv8engine_p.h>
#include <private/qdeclarativeglobal_p.h>

QT_BEGIN_HEADER

Expand Down Expand Up @@ -190,11 +191,12 @@ class QQuickVisualDataModelAttached : public QObject
Q_PROPERTY(bool isUnresolved READ isUnresolved NOTIFY unresolvedChanged)
public:
QQuickVisualDataModelAttached(QObject *parent)
: QObject(parent)
, m_cacheItem(0)
: m_cacheItem(0)
, m_previousGroups(0)
, m_modelChanged(false)
{}
{
QDeclarative_setParent_noEvent(this, parent);
}
~QQuickVisualDataModelAttached() { attachedProperties.remove(parent()); }

void setCacheItem(QQuickVisualDataModelItem *item);
Expand Down
4 changes: 3 additions & 1 deletion src/quick/items/qquickvisualdatamodel_p_p.h
Expand Up @@ -102,6 +102,7 @@ class QQuickVisualDataModelItem : public QObject, public QV8ObjectResource
{
Q_OBJECT
Q_PROPERTY(int index READ modelIndex NOTIFY modelIndexChanged)
Q_PROPERTY(QObject *model READ modelObject CONSTANT)
V8_RESOURCE_TYPE(VisualDataItemType)
public:
QQuickVisualDataModelItem(
Expand All @@ -120,6 +121,8 @@ class QQuickVisualDataModelItem : public QObject, public QV8ObjectResource

void Dispose();

QObject *modelObject() { return this; }

int modelIndex() const { return index[0]; }
void setModelIndex(int idx) { index[0] = idx; emit modelIndexChanged(); }

Expand Down Expand Up @@ -231,7 +234,6 @@ class QQuickVisualDataModelPrivate : public QObjectPrivate, public QQuickVisualD
void destroy(QObject *object);
QQuickVisualDataModel::ReleaseFlags release(QObject *object);
QString stringValue(Compositor::Group group, int index, const QString &name);
int cacheIndexOf(QObject *object) const;
void emitCreatedPackage(QQuickVisualDataModelItem *cacheItem, QDeclarativePackage *package);
void emitInitPackage(QQuickVisualDataModelItem *cacheItem, QDeclarativePackage *package);
void emitCreatedItem(QQuickVisualDataModelItem *cacheItem, QQuickItem *item) {
Expand Down

0 comments on commit ed36194

Please sign in to comment.