2121
2222#include " parser-cov.hh" // for KeyEventDigger
2323
24+ #include < stack>
25+
2426struct CovTreeDecoder ::Private {
2527 KeyEventDigger keDigger;
2628 InStream &input;
@@ -55,12 +57,34 @@ static DefEvent covDecodeEvt(const pt::ptree &evtNode)
5557 return evt;
5658}
5759
60+ struct CovEvtStackItem {
61+ const pt::ptree &evts;
62+ pt::ptree::const_iterator iter;
63+
64+ CovEvtStackItem (const pt::ptree &evts_):
65+ evts (evts_),
66+ iter (evts_.begin())
67+ {
68+ }
69+ };
70+
5871void CovTreeDecoder::Private::readEvents (Defect *def)
5972{
60- // go through the list of events
61- const pt::ptree &evtList = this ->pSrc ->get_child (" events" );
62- for (const auto &item : evtList) {
63- const pt::ptree &evtNode = item.second ;
73+ // stack to traverse events recursively (without recursive fnc call)
74+ std::stack<CovEvtStackItem> todo;
75+ todo.push (this ->pSrc ->get_child (" events" ));
76+
77+ do {
78+ CovEvtStackItem &si = todo.top ();
79+ if (si.evts .end () == si.iter ) {
80+ // no more events at this level to iterate through
81+ todo.pop ();
82+ continue ;
83+ }
84+
85+ // get current event and move to the next one
86+ const pt::ptree &evtNode = (si.iter ++)->second ;
87+
6488 if (evtNode.get <bool >(" main" )) {
6589 // this is a key event
6690
@@ -78,6 +102,7 @@ void CovTreeDecoder::Private::readEvents(Defect *def)
78102 const DefEvent evt = covDecodeEvt (evtNode);
79103 def->events .push_back (std::move (evt));
80104 }
105+ while (!todo.empty ());
81106}
82107
83108bool CovTreeDecoder::readNode (Defect *def)
0 commit comments