diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-03-03 14:54:31 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-03-04 13:54:50 +0000 |
commit | 5a9734c0d071b7490b3ef7edf5f080786dc89f79 (patch) | |
tree | ef8d18707d2f65df718ea785745d079ff3558fb8 /src/particles/qquickparticlesystem_p.h | |
parent | 554566788f585caaef14d929cee6557ad929e06e (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/qquickparticlesystem_p.h')
-rw-r--r-- | src/particles/qquickparticlesystem_p.h | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h index 9ddbb2ff38..2745e73053 100644 --- a/src/particles/qquickparticlesystem_p.h +++ b/src/particles/qquickparticlesystem_p.h @@ -65,6 +65,30 @@ QT_BEGIN_NAMESPACE +template<class T, int Prealloc> +class QQuickParticleVarLengthArray: public QVarLengthArray<T, Prealloc> +{ +public: + void insert(const T &element) + { + if (!this->contains(element)) { + this->append(element); + } + } + + bool removeOne(const T &element) + { + for (int i = 0; i < this->size(); ++i) { + if (this->at(i) == element) { + this->remove(i); + return true; + } + } + + return false; + } +}; + class QQuickParticleSystem; class QQuickParticleAffector; class QQuickParticleEmitter; @@ -110,6 +134,10 @@ private: }; class Q_QUICKPARTICLES_PRIVATE_EXPORT QQuickParticleGroupData { +public: // types + typedef int ID; + enum { InvalidID = -1, DefaultGroupID = 0 }; + public: QQuickParticleGroupData(const QString &name, QQuickParticleSystem* sys); ~QQuickParticleGroupData(); @@ -121,8 +149,8 @@ public: void setSize(int newSize); - const int index; - QSet<QQuickParticlePainter*> painters;//TODO: What if they are dynamically removed? + const ID index; + QQuickParticleVarLengthArray<QQuickParticlePainter*, 4> painters;//TODO: What if they are dynamically removed? //TODO: Refactor particle data list out into a separate class QVector<QQuickParticleData*> data; |