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,6 +54,8 @@ class JSON | ||
| 54 | { | 54 | { |
| 55 | public: | 55 | public: |
| 56 | static int constexpr LATEST = 2; | 56 | static int constexpr LATEST = 2; |
| 57 | + | ||
| 58 | + QPDF_DLL | ||
| 57 | JSON() = default; | 59 | JSON() = default; |
| 58 | 60 | ||
| 59 | QPDF_DLL | 61 | QPDF_DLL |
| @@ -369,7 +371,7 @@ class JSON | @@ -369,7 +371,7 @@ class JSON | ||
| 369 | } | 371 | } |
| 370 | virtual ~JSON_dictionary() = default; | 372 | virtual ~JSON_dictionary() = default; |
| 371 | virtual void write(Pipeline*, size_t depth) const; | 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 | std::set<std::string> parsed_keys; | 375 | std::set<std::string> parsed_keys; |
| 374 | }; | 376 | }; |
| 375 | struct JSON_array: public JSON_value | 377 | struct JSON_array: public JSON_value |
| @@ -380,7 +382,7 @@ class JSON | @@ -380,7 +382,7 @@ class JSON | ||
| 380 | } | 382 | } |
| 381 | virtual ~JSON_array() = default; | 383 | virtual ~JSON_array() = default; |
| 382 | virtual void write(Pipeline*, size_t depth) const; | 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 | struct JSON_string: public JSON_value | 387 | struct JSON_string: public JSON_value |
| 386 | { | 388 | { |
libqpdf/JSON.cc
| @@ -322,9 +322,9 @@ JSON::addArrayElement(JSON const& val) | @@ -322,9 +322,9 @@ JSON::addArrayElement(JSON const& val) | ||
| 322 | throw std::runtime_error("JSON::addArrayElement called on non-array"); | 322 | throw std::runtime_error("JSON::addArrayElement called on non-array"); |
| 323 | } | 323 | } |
| 324 | if (val.m->value.get()) { | 324 | if (val.m->value.get()) { |
| 325 | - arr->elements.push_back(val.m->value); | 325 | + arr->elements.push_back(val); |
| 326 | } else { | 326 | } else { |
| 327 | - arr->elements.push_back(std::make_shared<JSON_null>()); | 327 | + arr->elements.push_back(makeNull()); |
| 328 | } | 328 | } |
| 329 | return arr->elements.back(); | 329 | return arr->elements.back(); |
| 330 | } | 330 | } |
| @@ -504,11 +504,11 @@ JSON::checkSchemaInternal( | @@ -504,11 +504,11 @@ JSON::checkSchemaInternal( | ||
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | if (sch_dict && (!pattern_key.empty())) { | 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 | for (auto const& iter: this_dict->members) { | 508 | for (auto const& iter: this_dict->members) { |
| 509 | std::string const& key = iter.first; | 509 | std::string const& key = iter.first; |
| 510 | checkSchemaInternal( | 510 | checkSchemaInternal( |
| 511 | - this_dict->members[key].get(), | 511 | + this_dict->members[key].m->value.get(), |
| 512 | pattern_schema, | 512 | pattern_schema, |
| 513 | flags, | 513 | flags, |
| 514 | errors, | 514 | errors, |
| @@ -519,8 +519,8 @@ JSON::checkSchemaInternal( | @@ -519,8 +519,8 @@ JSON::checkSchemaInternal( | ||
| 519 | std::string const& key = iter.first; | 519 | std::string const& key = iter.first; |
| 520 | if (this_dict->members.count(key)) { | 520 | if (this_dict->members.count(key)) { |
| 521 | checkSchemaInternal( | 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 | flags, | 524 | flags, |
| 525 | errors, | 525 | errors, |
| 526 | prefix + "." + key); | 526 | prefix + "." + key); |
| @@ -557,8 +557,8 @@ JSON::checkSchemaInternal( | @@ -557,8 +557,8 @@ JSON::checkSchemaInternal( | ||
| 557 | int i = 0; | 557 | int i = 0; |
| 558 | for (auto const& element: this_arr->elements) { | 558 | for (auto const& element: this_arr->elements) { |
| 559 | checkSchemaInternal( | 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 | flags, | 562 | flags, |
| 563 | errors, | 563 | errors, |
| 564 | prefix + "." + std::to_string(i)); | 564 | prefix + "." + std::to_string(i)); |
| @@ -568,7 +568,7 @@ JSON::checkSchemaInternal( | @@ -568,7 +568,7 @@ JSON::checkSchemaInternal( | ||
| 568 | QTC::TC("libtests", "JSON schema array for single item"); | 568 | QTC::TC("libtests", "JSON schema array for single item"); |
| 569 | checkSchemaInternal( | 569 | checkSchemaInternal( |
| 570 | this_v, | 570 | this_v, |
| 571 | - sch_arr->elements.at(0).get(), | 571 | + sch_arr->elements.at(0).m->value.get(), |
| 572 | flags, | 572 | flags, |
| 573 | errors, | 573 | errors, |
| 574 | prefix); | 574 | prefix); |
| @@ -587,8 +587,8 @@ JSON::checkSchemaInternal( | @@ -587,8 +587,8 @@ JSON::checkSchemaInternal( | ||
| 587 | size_t i = 0; | 587 | size_t i = 0; |
| 588 | for (auto const& element: this_arr->elements) { | 588 | for (auto const& element: this_arr->elements) { |
| 589 | checkSchemaInternal( | 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 | flags, | 592 | flags, |
| 593 | errors, | 593 | errors, |
| 594 | prefix + "." + std::to_string(i)); | 594 | prefix + "." + std::to_string(i)); |