Skip to content

Commit 802fb19

Browse files
committed
parser-json-cov: simplify the code of readEvents()
No change in behavior intended with this commit. Related: #222
1 parent 746b8b4 commit 802fb19

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/lib/parser-json-cov.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,13 @@ CovTreeDecoder::~CovTreeDecoder() = default;
3737

3838
void CovTreeDecoder::Private::readEvents(Defect *def)
3939
{
40-
// count the events and allocate dst array
40+
// go through the list of events
4141
const pt::ptree &evtList = this->pSrc->get_child("events");
42-
def->events.resize(evtList.size());
43-
44-
// decode events one by one
45-
unsigned idx = 0;
46-
pt::ptree::const_iterator it;
47-
for (it = evtList.begin(); it != evtList.end(); ++it, ++idx) {
48-
const pt::ptree &evtNode = it->second;
49-
DefEvent &evt = def->events[idx];
42+
for (const auto &item : evtList) {
43+
const pt::ptree &evtNode = item.second;
5044

45+
// decode single event
46+
DefEvent evt;
5147
evt.fileName = valueOf<std::string>(evtNode, "filePathname");
5248
evt.line = valueOf<int> (evtNode, "lineNumber");
5349
evt.column = valueOf<int> (evtNode, "columnNumber");
@@ -57,7 +53,10 @@ void CovTreeDecoder::Private::readEvents(Defect *def)
5753
if (evtNode.get<bool>("main"))
5854
// this is a key event
5955
// TODO: detect and report re-definitions of key events
60-
def->keyEventIdx = idx;
56+
def->keyEventIdx = def->events.size();
57+
58+
// push the event to the list of events
59+
def->events.push_back(std::move(evt));
6160
}
6261
}
6362

0 commit comments

Comments
 (0)