aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@viroteck.net>2016-11-23 14:31:11 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-11-30 08:30:55 +0000
commit39496a40748be1d60c909ba679c45c788ec6412f (patch)
treea3a005d136b9d861a6a911b139b43eb9b8d20729 /src/qml/types
parentfca6857529f9be982a75cd055fdc01e8d34413fb (diff)
QQmlDelegateModel: Avoid allocating unnecessarily
Wait for the update request to be posted and take effect before piling another one up. This speeds up qmlbench creation benchmarks a bit (as they make use of Repeater). Results for benchmark/creation/delegates_item on a 5.6 base on a 2011 mbp: Before: Average: 670.4 ops/frame; using 5/5 samples; MedianAll=674; StdDev=6.34, CoV=0.00946 - StdDev (all samples included)=6.34 After: Average: 702 ops/frame; using 5/5 samples; MedianAll=700; StdDev=8.97, CoV=0.0128 - StdDev (all samples included)=8.97 Change-Id: Ic0ef4c1e2d6cb309edeb512cad4280a15abc7a06 Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/qml/types')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp23
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h3
2 files changed, 17 insertions, 9 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 9b58ec35f8..d9a8b1d179 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -213,6 +213,7 @@ QQmlDelegateModelPrivate::QQmlDelegateModelPrivate(QQmlContext *ctxt)
, m_reset(false)
, m_transaction(false)
, m_incubatorCleanupScheduled(false)
+ , m_waitingToFetchMore(false)
, m_cacheItems(0)
, m_items(0)
, m_persistedItems(0)
@@ -227,6 +228,15 @@ QQmlDelegateModelPrivate::~QQmlDelegateModelPrivate()
m_cacheMetaType->release();
}
+void QQmlDelegateModelPrivate::requestMoreIfNecessary()
+{
+ Q_Q(QQmlDelegateModel);
+ if (!m_waitingToFetchMore && m_adaptorModel.canFetchMore()) {
+ m_waitingToFetchMore = true;
+ QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest));
+ }
+}
+
void QQmlDelegateModelPrivate::init()
{
Q_Q(QQmlDelegateModel);
@@ -334,9 +344,7 @@ void QQmlDelegateModel::componentComplete()
&inserts);
d->itemsInserted(inserts);
d->emitChanges();
-
- if (d->m_adaptorModel.canFetchMore())
- QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
+ d->requestMoreIfNecessary();
}
/*!
@@ -375,8 +383,7 @@ void QQmlDelegateModel::setModel(const QVariant &model)
if (d->m_complete) {
_q_itemsInserted(0, d->m_adaptorModel.count());
- if (d->m_adaptorModel.canFetchMore())
- QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
+ d->requestMoreIfNecessary();
}
}
@@ -922,7 +929,6 @@ void QQmlDelegateModelPrivate::setInitialState(QQDMIncubationTask *incubationTas
QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, bool asynchronous)
{
- Q_Q(QQmlDelegateModel);
if (!m_delegate || index < 0 || index >= m_compositor.count(group)) {
qWarning() << "DelegateModel::item: index out range" << index << m_compositor.count(group);
return 0;
@@ -989,8 +995,8 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, bo
QQmlContextData::get(m_context));
}
- if (index == m_compositor.count(group) - 1 && m_adaptorModel.canFetchMore())
- QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest));
+ if (index == m_compositor.count(group) - 1)
+ requestMoreIfNecessary();
// Remove the temporary reference count.
cacheItem->scriptRef -= 1;
@@ -1110,6 +1116,7 @@ bool QQmlDelegateModel::event(QEvent *e)
{
Q_D(QQmlDelegateModel);
if (e->type() == QEvent::UpdateRequest) {
+ d->m_waitingToFetchMore = false;
d->m_adaptorModel.fetchMore();
} else if (e->type() == QEvent::User) {
d->m_incubatorCleanupScheduled = false;
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 6cb82fddfc..7d97358b3d 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -149,7 +149,6 @@ public:
int groups;
int index;
-
Q_SIGNALS:
void modelIndexChanged();
@@ -261,6 +260,7 @@ public:
void init();
void connectModel(QQmlAdaptorModel *model);
+ void requestMoreIfNecessary();
QObject *object(Compositor::Group group, int index, bool asynchronous);
QQmlDelegateModel::ReleaseFlags release(QObject *object);
QString stringValue(Compositor::Group group, int index, const QString &name);
@@ -329,6 +329,7 @@ public:
bool m_reset : 1;
bool m_transaction : 1;
bool m_incubatorCleanupScheduled : 1;
+ bool m_waitingToFetchMore : 1;
union {
struct {