From 5c488d4c46c0e5160c711e8d63592f487154db18 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 25 Jun 2014 10:45:18 +0000 Subject: [PATCH] From Mikhail Izmestev, "Attached fix to avoid vector usage in StateGraph::prune and reduce heap allocations." Notes from Robert Osfield, ammended the erase so that it explictly increments the iterator before the erase call. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14277 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgUtil/StateGraph.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/osgUtil/StateGraph.cpp b/src/osgUtil/StateGraph.cpp index ccad89e57..4f378f3f2 100644 --- a/src/osgUtil/StateGraph.cpp +++ b/src/osgUtil/StateGraph.cpp @@ -49,26 +49,17 @@ void StateGraph::clean() /** recursively prune the StateGraph of empty children.*/ void StateGraph::prune() { - std::vector toEraseList; - // call prune on all children. - for(ChildList::iterator citr=_children.begin(); - citr!=_children.end(); - ++citr) + ChildList::iterator citr=_children.begin(); + while(citr!=_children.end()) { citr->second->prune(); if (citr->second->empty()) { - toEraseList.push_back(citr->first); + ChildList::iterator ditr= citr++; + _children.erase(ditr); } + else ++citr; } - - for(std::vector::iterator eitr=toEraseList.begin(); - eitr!=toEraseList.end(); - ++eitr) - { - _children.erase(*eitr); - } - }