summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-10-29 18:25:14 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-10-30 18:49:47 +0100
commite99ae63aa871baee49670756f994ec5991f4a6da (patch)
treea27d97b0c6ac350409fee2374090c2a247cf7838
parente884779e6d008245ee82c0d4d12616c520b17136 (diff)
downloadqt3d-e99ae63aa871baee49670756f994ec5991f4a6da.tar.gz
Optimize QHash usage in RenderShader::updateUniforms.
It allocated a temporary QList of keys and repeatedly queried the items in the hash, incurring relatively slow QString hashing. Using iterators instead we can get rid of the temporary QList and safe the hash computations on the outer list. Profiling with Linux perf shows that the relative cost of this function drops from around 2.0% to less than 0.5%. Change-Id: Ic6a3c3ed7b6b4242e763a0b21987d543021de332 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/rendershader.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/render/backend/rendershader.cpp b/src/render/backend/rendershader.cpp
index acba247a1..f3c970f0a 100644
--- a/src/render/backend/rendershader.cpp
+++ b/src/render/backend/rendershader.cpp
@@ -150,9 +150,15 @@ QOpenGLShaderProgram *RenderShader::getOrCreateProgram(QGraphicsContext *ctx)
void RenderShader::updateUniforms(QGraphicsContext *ctx, const QUniformPack &pack)
{
const QHash<QString, const QUniformValue* > &values = pack.uniforms();
- Q_FOREACH (const QString &uniformName, values.keys()) {
- if (m_uniforms.contains(uniformName)) {
- values.value(uniformName)->apply(ctx, m_uniforms.value(uniformName));
+ QHash<QString, const QUniformValue* >::const_iterator valueIt = values.constBegin();
+ const QHash<QString, const QUniformValue* >::const_iterator valueEnd = values.constEnd();
+
+ const QHash<QString, ShaderUniform>::const_iterator uniformEnd = m_uniforms.constEnd();
+
+ for (; valueIt != valueEnd; ++valueIt) {
+ QHash<QString, ShaderUniform>::const_iterator uniformIt = m_uniforms.constFind(valueIt.key());
+ if (uniformIt != uniformEnd) {
+ valueIt.value()->apply(ctx, uniformIt.value());
}
}
}