From 7b1ee2780b16652406cbfae21e5936f425489aa5 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 25 Dec 2023 14:17:12 +0100 Subject: [PATCH] Use ranged for loops in GenericObjectCache --- components/resource/objectcache.hpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/components/resource/objectcache.hpp b/components/resource/objectcache.hpp index 9cb74c762c..8f99e6dfda 100644 --- a/components/resource/objectcache.hpp +++ b/components/resource/objectcache.hpp @@ -139,26 +139,18 @@ namespace Resource void releaseGLObjects(osg::State* state) { std::lock_guard lock(_objectCacheMutex); - for (typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) - { - osg::Object* object = itr->second.mValue.get(); - object->releaseGLObjects(state); - } + for (const auto& [k, v] : _objectCache) + v.mValue->releaseGLObjects(state); } /** call node->accept(nv); for all nodes in the objectCache. */ void accept(osg::NodeVisitor& nv) { std::lock_guard lock(_objectCacheMutex); - for (typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) - { - if (osg::Object* object = itr->second.mValue.get()) - { - osg::Node* node = dynamic_cast(object); - if (node) + for (const auto& [k, v] : _objectCache) + if (osg::Object* const object = v.mValue.get()) + if (osg::Node* const node = dynamic_cast(object)) node->accept(nv); - } - } } /** call operator()(KeyType, osg::Object*) for each object in the cache. */ @@ -166,8 +158,8 @@ namespace Resource void call(Functor&& f) { std::lock_guard lock(_objectCacheMutex); - for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it) - f(it->first, it->second.mValue.get()); + for (const auto& [k, v] : _objectCache) + f(k, v.mValue.get()); } /** Get the number of objects in the cache. */