aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickparticlepainter_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-03-03 14:54:31 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-03-04 13:54:50 +0000
commit5a9734c0d071b7490b3ef7edf5f080786dc89f79 (patch)
treeef8d18707d2f65df718ea785745d079ff3558fb8 /src/particles/qquickparticlepainter_p.h
parent554566788f585caaef14d929cee6557ad929e06e (diff)
Particles: reduce excessive hash accesses to a more passable level.
By caching the group id in the particle emitter, and groups in the painter. Test case: samegame, 1 player, click 1 set of 3 stones, quit. QQuickParticleSystem::emittersChanged(), before patch: - 64M instr. inclusive - 145,880 calls to findNode (29M instr.) after: - 21M instr. inclusive - 0 calls to findNode - 25 calls to QQuickParticlePainter::recalculateGroupIds (9800 instr. inclusive). Change-Id: I4aba9d50100513c6b7cdd230e30b3aecaf84485a Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/particles/qquickparticlepainter_p.h')
-rw-r--r--src/particles/qquickparticlepainter_p.h37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/particles/qquickparticlepainter_p.h b/src/particles/qquickparticlepainter_p.h
index 719dfdb3d8..064ce27fe8 100644
--- a/src/particles/qquickparticlepainter_p.h
+++ b/src/particles/qquickparticlepainter_p.h
@@ -64,25 +64,40 @@ class QQuickParticlePainter : public QQuickItem
Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
+public: // data
+ typedef QQuickParticleVarLengthArray<QQuickParticleGroupData::ID, 4> GroupIDs;
+
public:
explicit QQuickParticlePainter(QQuickItem *parent = 0);
//Data Interface to system
void load(QQuickParticleData*);
void reload(QQuickParticleData*);
void setCount(int c);
- int count();
+
+ int count() const
+ {
+ return m_count;
+ }
+
void performPendingCommits();//Called from updatePaintNode
QQuickParticleSystem* system() const
{
return m_system;
}
-
QStringList groups() const
{
return m_groups;
}
+ const GroupIDs &groupIds() const
+ {
+ if (m_groupIdsNeedRecalculation) {
+ recalculateGroupIds();
+ }
+ return m_groupIds;
+ }
+
void itemChange(ItemChange, const ItemChangeData &);
Q_SIGNALS:
@@ -94,14 +109,7 @@ Q_SIGNALS:
public Q_SLOTS:
void setSystem(QQuickParticleSystem* arg);
- void setGroups(const QStringList &arg)
- {
- if (m_groups != arg) {
- m_groups = arg;
- //Note: The system watches this as it has to recalc things when groups change. It will request a reset if necessary
- Q_EMIT groupsChanged(arg);
- }
- }
+ void setGroups(const QStringList &arg);
void calcSystemOffset(bool resetPending = false);
@@ -130,13 +138,18 @@ protected:
friend class QQuickParticleSystem;
int m_count;
bool m_pleaseReset;//Used by subclasses, but it's a nice optimization to know when stuff isn't going to matter.
- QStringList m_groups;
QPointF m_systemOffset;
QQuickWindow *m_window;
-private:
+private: // methods
+ void recalculateGroupIds() const;
+
+private: // data
+ QStringList m_groups;
QSet<QPair<int,int> > m_pendingCommits;
+ mutable GroupIDs m_groupIds;
+ mutable bool m_groupIdsNeedRecalculation;
};
QT_END_NAMESPACE