summaryrefslogtreecommitdiffstats
path: root/src/render/io
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-12-03 15:58:41 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-09 18:54:12 +0100
commit8d553fdf952b79dc79447392161f97ff866cfcb9 (patch)
treede8d846581ac77de904fdbfb8f63a0dd9679a8e0 /src/render/io
parent4469b3185602ee494fc8cdcae37c29dd8f1b7574 (diff)
Optimize: Remove temporary allocations in QMeshData::attributeNames.
This is called frequently and was previously triggering many temporary data allocations. By using a separated QStringList and QVector, we can keep the behavior of the QHash and can remove the temporaries. Change-Id: Idd7db916341037e98b78730d4f599990041ec706 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/qmeshdata.cpp24
-rw-r--r--src/render/io/qmeshdata.h6
-rw-r--r--src/render/io/qmeshdata_p.h3
3 files changed, 22 insertions, 11 deletions
diff --git a/src/render/io/qmeshdata.cpp b/src/render/io/qmeshdata.cpp
index af26770a2..08cd1da09 100644
--- a/src/render/io/qmeshdata.cpp
+++ b/src/render/io/qmeshdata.cpp
@@ -71,13 +71,19 @@ QMeshData::QMeshData(QMeshDataPrivate &dd)
{
}
-void QMeshData::addAttribute(const QString &name, QAbstractAttributePtr attr)
+void QMeshData::addAttribute(const QString &name, const QAbstractAttributePtr &attr)
{
Q_D(QMeshData);
- d->m_attributes.insert(name, attr);
+ const int i = d->m_attributesNames.indexOf(name);
+ if (i != -1) {
+ d->m_attributes[i] = attr;
+ } else {
+ d->m_attributesNames.append(name);
+ d->m_attributes.append(attr);
+ }
}
-void QMeshData::setIndexAttribute(QAbstractAttributePtr attr)
+void QMeshData::setIndexAttribute(const QAbstractAttributePtr &attr)
{
Q_D(QMeshData);
d->m_indexAttr = attr;
@@ -86,13 +92,17 @@ void QMeshData::setIndexAttribute(QAbstractAttributePtr attr)
QStringList QMeshData::attributeNames() const
{
Q_D(const QMeshData);
- return d->m_attributes.keys();
+ return d->m_attributesNames;
}
-QAbstractAttributePtr QMeshData::attributeByName(QString name) const
+QAbstractAttributePtr QMeshData::attributeByName(const QString &name) const
{
Q_D(const QMeshData);
- return d->m_attributes.value(name);
+ const int i = d->m_attributesNames.indexOf(name);
+ if (i != -1)
+ return d->m_attributes[i];
+ else
+ return QAbstractAttributePtr();
}
QAbstractAttributePtr QMeshData::indexAttribute() const
@@ -134,7 +144,7 @@ QList<QAbstractBufferPtr> QMeshData::buffers() const
if (d->m_indexAttr)
r.insert(d->m_indexAttr->buffer());
- Q_FOREACH (QAbstractAttributePtr v, d->m_attributes.values())
+ Q_FOREACH (const QAbstractAttributePtr &v, d->m_attributes)
r.insert(v->buffer());
return r.toList();
diff --git a/src/render/io/qmeshdata.h b/src/render/io/qmeshdata.h
index 613f1190a..20b4008fb 100644
--- a/src/render/io/qmeshdata.h
+++ b/src/render/io/qmeshdata.h
@@ -78,11 +78,11 @@ public:
explicit QMeshData(PrimitiveTypes primitiveType = Triangles);
virtual ~QMeshData();
- void addAttribute(const QString& name, QAbstractAttributePtr attr);
- void setIndexAttribute(QAbstractAttributePtr attr);
+ void addAttribute(const QString &name, const QAbstractAttributePtr &attr);
+ void setIndexAttribute(const QAbstractAttributePtr &attr);
QStringList attributeNames() const;
- QAbstractAttributePtr attributeByName(QString name) const;
+ QAbstractAttributePtr attributeByName(const QString &name) const;
QAbstractAttributePtr indexAttribute() const;
static const QString defaultPositionAttributeName() { return QStringLiteral("vertexPosition"); }
diff --git a/src/render/io/qmeshdata_p.h b/src/render/io/qmeshdata_p.h
index 4774d5915..6e74b2370 100644
--- a/src/render/io/qmeshdata_p.h
+++ b/src/render/io/qmeshdata_p.h
@@ -66,7 +66,8 @@ public:
Q_DECLARE_PUBLIC(QMeshData)
QMeshData *q_ptr;
- QMap<QString, QAbstractAttributePtr> m_attributes;
+ QStringList m_attributesNames;
+ QVector<QAbstractAttributePtr> m_attributes;
QAbstractAttributePtr m_indexAttr;
QAxisAlignedBoundingBox m_bbox;
int m_verticesPerPatch;