diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-05-02 14:06:42 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-05 17:32:21 +0000 |
commit | b76bc40c960b67b6b35aa809bffc5ef0232b7d13 (patch) | |
tree | b560e8b7d32fdd14fbeba983a42e929609a0a65e /src/plugins/sceneparsers/gltf/gltfio.cpp | |
parent | 2cc5f306e100de1edf9f8f9fd9fa4da8c5f81a4a (diff) |
GLTFIO: don't iterate over QMap::values()
... iterate using (const_)iterators instead.
This avoids the creation of a temporary QList to hold the
keys as well as the following binary search inside value()
on each iteration.
Factored common code into a helper function as a drive-by.
Saves almost 5KiB in text size on optimized GCC 6.0 Linux
AMD64 builds.
Change-Id: Ie0cc7e7c353cd08a5dd68de6129eb24a9ec243c8
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins/sceneparsers/gltf/gltfio.cpp')
-rw-r--r-- | src/plugins/sceneparsers/gltf/gltfio.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/plugins/sceneparsers/gltf/gltfio.cpp b/src/plugins/sceneparsers/gltf/gltfio.cpp index d13568610..ec2ccb5a4 100644 --- a/src/plugins/sceneparsers/gltf/gltfio.cpp +++ b/src/plugins/sceneparsers/gltf/gltfio.cpp @@ -819,37 +819,32 @@ void GLTFIO::parse() m_parseDone = true; } +namespace { +template <typename C> +void delete_if_without_parent(const C &c) +{ + for (const auto *e : c) { + if (!e->parent()) + delete e; + } +} +} // unnamed namespace + void GLTFIO::cleanup() { m_meshDict.clear(); m_meshMaterialDict.clear(); m_accessorDict.clear(); - //Check for Materials with no parent - Q_FOREACH (QMaterial *material, m_materialCache.values()) { - if (material->parent() == nullptr) - delete material; - } + delete_if_without_parent(m_materialCache); m_materialCache.clear(); m_bufferDatas.clear(); m_buffers.clear(); m_shaderPaths.clear(); - //Check for ShaderPrograms with no parent - Q_FOREACH (QShaderProgram *program, m_programs.values()) { - if (program->parent() == nullptr) - delete program; - } + delete_if_without_parent(m_programs); m_programs.clear(); - //Check for Techniques with no parent - Q_FOREACH (QTechnique *technique, m_techniques.values()) { - if (technique->parent() == nullptr) - delete technique; - } + delete_if_without_parent(m_techniques); m_techniques.clear(); - //Check for Textures with no parent - Q_FOREACH (QAbstractTexture *texture, m_textures.values()) { - if (texture->parent() == nullptr) - delete texture; - } + delete_if_without_parent(m_textures); m_textures.clear(); m_imagePaths.clear(); m_defaultScene.clear(); |