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
This commit is contained in:
Robert Osfield 2014-06-25 10:45:18 +00:00
parent 4e530a1938
commit 5c488d4c46

View File

@ -49,26 +49,17 @@ void StateGraph::clean()
/** recursively prune the StateGraph of empty children.*/ /** recursively prune the StateGraph of empty children.*/
void StateGraph::prune() void StateGraph::prune()
{ {
std::vector<const osg::StateSet*> toEraseList;
// call prune on all children. // call prune on all children.
for(ChildList::iterator citr=_children.begin(); ChildList::iterator citr=_children.begin();
citr!=_children.end(); while(citr!=_children.end())
++citr)
{ {
citr->second->prune(); citr->second->prune();
if (citr->second->empty()) if (citr->second->empty())
{ {
toEraseList.push_back(citr->first); ChildList::iterator ditr= citr++;
_children.erase(ditr);
} }
else ++citr;
} }
for(std::vector<const osg::StateSet*>::iterator eitr=toEraseList.begin();
eitr!=toEraseList.end();
++eitr)
{
_children.erase(*eitr);
}
} }