Commit a4f3dddb79e875bae74b8d4f3ebd6a94076e8a9e
1 parent
b4c36d9b
Change JSON_dictionary and JSON_array to store JSON objects rather than std::shared_ptr<JSON_value>
Recognise that JSON objects are effectively shared pointers to JSON_value.
Showing
2 changed files
with
15 additions
and
13 deletions
include/qpdf/JSON.hh
| ... | ... | @@ -54,6 +54,8 @@ class JSON |
| 54 | 54 | { |
| 55 | 55 | public: |
| 56 | 56 | static int constexpr LATEST = 2; |
| 57 | + | |
| 58 | + QPDF_DLL | |
| 57 | 59 | JSON() = default; |
| 58 | 60 | |
| 59 | 61 | QPDF_DLL |
| ... | ... | @@ -369,7 +371,7 @@ class JSON |
| 369 | 371 | } |
| 370 | 372 | virtual ~JSON_dictionary() = default; |
| 371 | 373 | virtual void write(Pipeline*, size_t depth) const; |
| 372 | - std::map<std::string, std::shared_ptr<JSON_value>> members; | |
| 374 | + std::map<std::string, JSON> members; | |
| 373 | 375 | std::set<std::string> parsed_keys; |
| 374 | 376 | }; |
| 375 | 377 | struct JSON_array: public JSON_value |
| ... | ... | @@ -380,7 +382,7 @@ class JSON |
| 380 | 382 | } |
| 381 | 383 | virtual ~JSON_array() = default; |
| 382 | 384 | virtual void write(Pipeline*, size_t depth) const; |
| 383 | - std::vector<std::shared_ptr<JSON_value>> elements; | |
| 385 | + std::vector<JSON> elements; | |
| 384 | 386 | }; |
| 385 | 387 | struct JSON_string: public JSON_value |
| 386 | 388 | { | ... | ... |
libqpdf/JSON.cc
| ... | ... | @@ -322,9 +322,9 @@ JSON::addArrayElement(JSON const& val) |
| 322 | 322 | throw std::runtime_error("JSON::addArrayElement called on non-array"); |
| 323 | 323 | } |
| 324 | 324 | if (val.m->value.get()) { |
| 325 | - arr->elements.push_back(val.m->value); | |
| 325 | + arr->elements.push_back(val); | |
| 326 | 326 | } else { |
| 327 | - arr->elements.push_back(std::make_shared<JSON_null>()); | |
| 327 | + arr->elements.push_back(makeNull()); | |
| 328 | 328 | } |
| 329 | 329 | return arr->elements.back(); |
| 330 | 330 | } |
| ... | ... | @@ -504,11 +504,11 @@ JSON::checkSchemaInternal( |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | if (sch_dict && (!pattern_key.empty())) { |
| 507 | - auto pattern_schema = sch_dict->members[pattern_key].get(); | |
| 507 | + auto pattern_schema = sch_dict->members[pattern_key].m->value.get(); | |
| 508 | 508 | for (auto const& iter: this_dict->members) { |
| 509 | 509 | std::string const& key = iter.first; |
| 510 | 510 | checkSchemaInternal( |
| 511 | - this_dict->members[key].get(), | |
| 511 | + this_dict->members[key].m->value.get(), | |
| 512 | 512 | pattern_schema, |
| 513 | 513 | flags, |
| 514 | 514 | errors, |
| ... | ... | @@ -519,8 +519,8 @@ JSON::checkSchemaInternal( |
| 519 | 519 | std::string const& key = iter.first; |
| 520 | 520 | if (this_dict->members.count(key)) { |
| 521 | 521 | checkSchemaInternal( |
| 522 | - this_dict->members[key].get(), | |
| 523 | - iter.second.get(), | |
| 522 | + this_dict->members[key].m->value.get(), | |
| 523 | + iter.second.m->value.get(), | |
| 524 | 524 | flags, |
| 525 | 525 | errors, |
| 526 | 526 | prefix + "." + key); |
| ... | ... | @@ -557,8 +557,8 @@ JSON::checkSchemaInternal( |
| 557 | 557 | int i = 0; |
| 558 | 558 | for (auto const& element: this_arr->elements) { |
| 559 | 559 | checkSchemaInternal( |
| 560 | - element.get(), | |
| 561 | - sch_arr->elements.at(0).get(), | |
| 560 | + element.m->value.get(), | |
| 561 | + sch_arr->elements.at(0).m->value.get(), | |
| 562 | 562 | flags, |
| 563 | 563 | errors, |
| 564 | 564 | prefix + "." + std::to_string(i)); |
| ... | ... | @@ -568,7 +568,7 @@ JSON::checkSchemaInternal( |
| 568 | 568 | QTC::TC("libtests", "JSON schema array for single item"); |
| 569 | 569 | checkSchemaInternal( |
| 570 | 570 | this_v, |
| 571 | - sch_arr->elements.at(0).get(), | |
| 571 | + sch_arr->elements.at(0).m->value.get(), | |
| 572 | 572 | flags, |
| 573 | 573 | errors, |
| 574 | 574 | prefix); |
| ... | ... | @@ -587,8 +587,8 @@ JSON::checkSchemaInternal( |
| 587 | 587 | size_t i = 0; |
| 588 | 588 | for (auto const& element: this_arr->elements) { |
| 589 | 589 | checkSchemaInternal( |
| 590 | - element.get(), | |
| 591 | - sch_arr->elements.at(i).get(), | |
| 590 | + element.m->value.get(), | |
| 591 | + sch_arr->elements.at(i).m->value.get(), | |
| 592 | 592 | flags, |
| 593 | 593 | errors, |
| 594 | 594 | prefix + "." + std::to_string(i)); | ... | ... |