From cb08f490d7efb9d4cede6edbfadec1f2af650aca Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 29 Aug 2021 15:15:45 +0200 Subject: [PATCH] Sprinkle some const-ref in loop This was done on the good advices of clang-tidy --- components/resource/keyframemanager.cpp | 2 +- components/shader/shadermanager.cpp | 17 ++++++++--------- components/terrain/buffercache.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 77c31d9ad7..444d2bd7aa 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -30,7 +30,7 @@ namespace Resource std::vector emulatedAnimations; - for (auto animation : mAnimationManager->getAnimationList()) + for (const auto& animation : mAnimationManager->getAnimationList()) { if (animation) { diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index 9b057cdfc6..33f79415f1 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -371,11 +371,10 @@ namespace Shader void ShaderManager::setGlobalDefines(DefineMap & globalDefines) { mGlobalDefines = globalDefines; - for (auto shaderMapElement: mShaders) + for (const auto& [key, shader]: mShaders) { - std::string templateId = shaderMapElement.first.first; - ShaderManager::DefineMap defines = shaderMapElement.first.second; - osg::ref_ptr shader = shaderMapElement.second; + std::string templateId = key.first; + ShaderManager::DefineMap defines = key.second; if (shader == nullptr) // I'm not sure how to handle a shader that was already broken as there's no way to get a potential replacement to the nodes that need it. continue; @@ -391,13 +390,13 @@ namespace Shader void ShaderManager::releaseGLObjects(osg::State *state) { std::lock_guard lock(mMutex); - for (auto shader : mShaders) + for (const auto& [_, shader] : mShaders) { - if (shader.second != nullptr) - shader.second->releaseGLObjects(state); + if (shader != nullptr) + shader->releaseGLObjects(state); } - for (auto program : mPrograms) - program.second->releaseGLObjects(state); + for (const auto& [_, program] : mPrograms) + program->releaseGLObjects(state); } } diff --git a/components/terrain/buffercache.cpp b/components/terrain/buffercache.cpp index f9eb7ae635..399df16d34 100644 --- a/components/terrain/buffercache.cpp +++ b/components/terrain/buffercache.cpp @@ -245,13 +245,13 @@ namespace Terrain { { std::lock_guard lock(mIndexBufferMutex); - for (auto indexbuffer : mIndexBufferMap) - indexbuffer.second->releaseGLObjects(state); + for (const auto& [_, indexbuffer] : mIndexBufferMap) + indexbuffer->releaseGLObjects(state); } { std::lock_guard lock(mUvBufferMutex); - for (auto uvbuffer : mUvBufferMap) - uvbuffer.second->releaseGLObjects(state); + for (const auto& [_, uvbuffer] : mUvBufferMap) + uvbuffer->releaseGLObjects(state); } }