Skip to content

Commit e3e4b53

Browse files
committed
json-reader: optimize to reduce memory consumption
... by avoiding an unnecessary deep copy of the property tree object representing the whole input. massif's output for a chosen sample data follows. Before this commit ================== MB 671.9^ ## | # | # | # | # | @@# | @ # | @ # | @@ # | @@ # | @@ # :::::::::@::::@@::::@:::: | @::::@@ # : :: :: :@: ::@ ::: @::: | @@@@@: : @@ # : :: :: :@: ::@ ::: @::: | :@@:@@@ @: : @@ # : :: :: :@: ::@ ::: @::: | @@:::@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : | @@@@@ : :@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : | @@@@@@ @ : :@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : | @@:::@@ @@@ @ : :@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : | @@@@@ :: @@ @@@ @ : :@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : | @@@@@@ @@ :: @@ @@@ @ : :@ :@@@ @: : @@ # : :: :: :@: ::@ ::: @::: : 0 +----------------------------------------------------------------------->Gi 0 8.835 After this commit ================= MB 340.4^ : | @##:::@:::@:::@::::::@:::::@: | @@@# :: @:::@:: @::::::@:::::@: | @@@ @# :: @:::@:: @::::::@:::::@: | @@@@ @ @# :: @:::@:: @::::::@:::::@: | ::@ @@ @ @# :: @:::@:: @::::::@:::::@: | ::::@ @@ @ @# :: @:::@:: @::::::@:::::@: | @@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@: | @@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | :@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@@@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @:@@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @::@ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@: @ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@@@: @ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@ @@@: @ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@@@ @@@: @ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: | @@@@@@@ @@@: @ @@ @@@::@@@@@: ::@ @@ @ @# :: @:::@:: @::::::@:::::@:: 0 +----------------------------------------------------------------------->Gi 0 8.126
1 parent d743ced commit e3e4b53

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

json-parser.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct JsonParser::Private {
3737
const bool silent;
3838
bool jsonValid;
3939
bool hasError;
40-
pt::ptree defList;
40+
pt::ptree root;
41+
pt::ptree *defList;
4142
pt::ptree::const_iterator defIter;
4243
int defNumber;
4344
TScanProps scanProps;
@@ -91,17 +92,17 @@ JsonParser::JsonParser(
9192
{
9293
try {
9394
// parse JSON
94-
pt::ptree root;
95-
read_json(input, root);
95+
read_json(input, d->root);
9696

9797
// get the defect list
98-
d->defList = root.get_child("defects");
99-
d->defIter = d->defList.begin();
98+
d->defList = &d->root.get_child("defects");
99+
d->defIter = d->defList->begin();
100100
d->jsonValid = true;
101101

102102
// read scan properties if available
103103
pt::ptree emp;
104-
pt::ptree scanNode = root.get_child_optional("scan").get_value_or(emp);
104+
pt::ptree scanNode =
105+
d->root.get_child_optional("scan").get_value_or(emp);
105106
BOOST_FOREACH(const pt::ptree::value_type &item, scanNode)
106107
d->scanProps[item.first] = item.second.data();
107108
}
@@ -214,7 +215,7 @@ bool JsonParser::getNext(Defect *def) {
214215

215216
// error recovery loop
216217
for (;;) {
217-
if (d->defList.end() == d->defIter)
218+
if (d->defList->end() == d->defIter)
218219
return false;
219220

220221
if (d->readNext(def))

0 commit comments

Comments
 (0)