Commit 7ae1e80fd6626ce07262656a7d822e68004754ae
1 parent
a4f3dddb
Change JSON::Members::value to std::unique_ptr
Showing
2 changed files
with
19 additions
and
21 deletions
include/qpdf/JSON.hh
| ... | ... | @@ -425,7 +425,7 @@ class JSON |
| 425 | 425 | std::function<void(Pipeline*)> fn; |
| 426 | 426 | }; |
| 427 | 427 | |
| 428 | - JSON(std::shared_ptr<JSON_value>); | |
| 428 | + JSON(std::unique_ptr<JSON_value>); | |
| 429 | 429 | |
| 430 | 430 | static bool checkSchemaInternal( |
| 431 | 431 | JSON_value* this_v, |
| ... | ... | @@ -443,13 +443,13 @@ class JSON |
| 443 | 443 | ~Members() = default; |
| 444 | 444 | |
| 445 | 445 | private: |
| 446 | - Members(std::shared_ptr<JSON_value>); | |
| 446 | + Members(std::unique_ptr<JSON_value>); | |
| 447 | 447 | Members(Members const&) = delete; |
| 448 | 448 | |
| 449 | - std::shared_ptr<JSON_value> value; | |
| 449 | + std::unique_ptr<JSON_value> value; | |
| 450 | 450 | // start and end are only populated for objects created by parse |
| 451 | - qpdf_offset_t start; | |
| 452 | - qpdf_offset_t end; | |
| 451 | + qpdf_offset_t start{0}; | |
| 452 | + qpdf_offset_t end{0}; | |
| 453 | 453 | }; |
| 454 | 454 | |
| 455 | 455 | std::shared_ptr<Members> m; | ... | ... |
libqpdf/JSON.cc
| ... | ... | @@ -9,15 +9,13 @@ |
| 9 | 9 | #include <cstring> |
| 10 | 10 | #include <stdexcept> |
| 11 | 11 | |
| 12 | -JSON::Members::Members(std::shared_ptr<JSON_value> value) : | |
| 13 | - value(value), | |
| 14 | - start(0), | |
| 15 | - end(0) | |
| 12 | +JSON::Members::Members(std::unique_ptr<JSON_value> value) : | |
| 13 | + value(std::move(value)) | |
| 16 | 14 | { |
| 17 | 15 | } |
| 18 | 16 | |
| 19 | -JSON::JSON(std::shared_ptr<JSON_value> value) : | |
| 20 | - m(new Members(value)) | |
| 17 | +JSON::JSON(std::unique_ptr<JSON_value> value) : | |
| 18 | + m(new Members(std::move(value))) | |
| 21 | 19 | { |
| 22 | 20 | } |
| 23 | 21 | |
| ... | ... | @@ -278,7 +276,7 @@ JSON::encode_string(std::string const& str) |
| 278 | 276 | JSON |
| 279 | 277 | JSON::makeDictionary() |
| 280 | 278 | { |
| 281 | - return JSON(std::make_shared<JSON_dictionary>()); | |
| 279 | + return JSON(std::make_unique<JSON_dictionary>()); | |
| 282 | 280 | } |
| 283 | 281 | |
| 284 | 282 | JSON |
| ... | ... | @@ -286,7 +284,7 @@ JSON::addDictionaryMember(std::string const& key, JSON const& val) |
| 286 | 284 | { |
| 287 | 285 | if (auto* obj = dynamic_cast<JSON_dictionary*>(this->m->value.get())) { |
| 288 | 286 | return obj->members[encode_string(key)] = |
| 289 | - val.m->value ? val.m->value : std::make_shared<JSON_null>(); | |
| 287 | + val.m->value ? val : makeNull(); | |
| 290 | 288 | } else { |
| 291 | 289 | throw std::runtime_error( |
| 292 | 290 | "JSON::addDictionaryMember called on non-dictionary"); |
| ... | ... | @@ -311,7 +309,7 @@ JSON::checkDictionaryKeySeen(std::string const& key) |
| 311 | 309 | JSON |
| 312 | 310 | JSON::makeArray() |
| 313 | 311 | { |
| 314 | - return JSON(std::make_shared<JSON_array>()); | |
| 312 | + return JSON(std::make_unique<JSON_array>()); | |
| 315 | 313 | } |
| 316 | 314 | |
| 317 | 315 | JSON |
| ... | ... | @@ -332,43 +330,43 @@ JSON::addArrayElement(JSON const& val) |
| 332 | 330 | JSON |
| 333 | 331 | JSON::makeString(std::string const& utf8) |
| 334 | 332 | { |
| 335 | - return JSON(std::make_shared<JSON_string>(utf8)); | |
| 333 | + return JSON(std::make_unique<JSON_string>(utf8)); | |
| 336 | 334 | } |
| 337 | 335 | |
| 338 | 336 | JSON |
| 339 | 337 | JSON::makeInt(long long int value) |
| 340 | 338 | { |
| 341 | - return JSON(std::make_shared<JSON_number>(value)); | |
| 339 | + return JSON(std::make_unique<JSON_number>(value)); | |
| 342 | 340 | } |
| 343 | 341 | |
| 344 | 342 | JSON |
| 345 | 343 | JSON::makeReal(double value) |
| 346 | 344 | { |
| 347 | - return JSON(std::make_shared<JSON_number>(value)); | |
| 345 | + return JSON(std::make_unique<JSON_number>(value)); | |
| 348 | 346 | } |
| 349 | 347 | |
| 350 | 348 | JSON |
| 351 | 349 | JSON::makeNumber(std::string const& encoded) |
| 352 | 350 | { |
| 353 | - return JSON(std::make_shared<JSON_number>(encoded)); | |
| 351 | + return JSON(std::make_unique<JSON_number>(encoded)); | |
| 354 | 352 | } |
| 355 | 353 | |
| 356 | 354 | JSON |
| 357 | 355 | JSON::makeBool(bool value) |
| 358 | 356 | { |
| 359 | - return JSON(std::make_shared<JSON_bool>(value)); | |
| 357 | + return JSON(std::make_unique<JSON_bool>(value)); | |
| 360 | 358 | } |
| 361 | 359 | |
| 362 | 360 | JSON |
| 363 | 361 | JSON::makeNull() |
| 364 | 362 | { |
| 365 | - return JSON(std::make_shared<JSON_null>()); | |
| 363 | + return JSON(std::make_unique<JSON_null>()); | |
| 366 | 364 | } |
| 367 | 365 | |
| 368 | 366 | JSON |
| 369 | 367 | JSON::makeBlob(std::function<void(Pipeline*)> fn) |
| 370 | 368 | { |
| 371 | - return JSON(std::make_shared<JSON_blob>(fn)); | |
| 369 | + return JSON(std::make_unique<JSON_blob>(fn)); | |
| 372 | 370 | } |
| 373 | 371 | |
| 374 | 372 | bool | ... | ... |