21
21
22
22
#include " parser-cov.hh" // for KeyEventDigger
23
23
24
+ #include < stack>
25
+
24
26
struct CovTreeDecoder ::Private {
25
27
KeyEventDigger keDigger;
26
28
InStream &input;
@@ -55,12 +57,34 @@ static DefEvent covDecodeEvt(const pt::ptree &evtNode)
55
57
return evt;
56
58
}
57
59
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
+
58
71
void CovTreeDecoder::Private::readEvents (Defect *def)
59
72
{
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
+
64
88
if (evtNode.get <bool >(" main" )) {
65
89
// this is a key event
66
90
@@ -78,6 +102,7 @@ void CovTreeDecoder::Private::readEvents(Defect *def)
78
102
DefEvent evt = covDecodeEvt (evtNode);
79
103
def->events .push_back (std::move (evt));
80
104
}
105
+ while (!todo.empty ());
81
106
}
82
107
83
108
bool CovTreeDecoder::readNode (Defect *def)
0 commit comments