Skip to content

Commit 72aa42a

Browse files
committed
parser-json-cov: use a stack in readEvents()
... to make the code ready for processing nested events. No change in behavior with this commit yet. Related: #222
1 parent 5a10a5d commit 72aa42a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

Diff for: src/lib/parser-json-cov.cc

+29-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include "parser-cov.hh" // for KeyEventDigger
2323

24+
#include <stack>
25+
2426
struct 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+
5871
void 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
DefEvent evt = covDecodeEvt(evtNode);
79103
def->events.push_back(std::move(evt));
80104
}
105+
while (!todo.empty());
81106
}
82107

83108
bool CovTreeDecoder::readNode(Defect *def)

0 commit comments

Comments
 (0)