Commit dca5927ba0e57c7046a93213e05bfa6eda130707
1 parent
b85a590b
Tweak Handlers::json_handlers
Use std::vector instead of list and move shared pointers
Showing
1 changed file
with
6 additions
and
4 deletions
libqpdf/QPDFJob_json.cc
| @@ -59,7 +59,7 @@ namespace | @@ -59,7 +59,7 @@ namespace | ||
| 59 | 59 | ||
| 60 | void beginUnderOverlay(JSON const& j); | 60 | void beginUnderOverlay(JSON const& j); |
| 61 | 61 | ||
| 62 | - std::list<std::shared_ptr<JSONHandler>> json_handlers; | 62 | + std::vector<std::shared_ptr<JSONHandler>> json_handlers; |
| 63 | bool partial; | 63 | bool partial; |
| 64 | JSONHandler* jh{nullptr}; // points to last of json_handlers | 64 | JSONHandler* jh{nullptr}; // points to last of json_handlers |
| 65 | std::shared_ptr<QPDFJob::Config> c_main; | 65 | std::shared_ptr<QPDFJob::Config> c_main; |
| @@ -100,7 +100,7 @@ Handlers::bindJSON(void (Handlers::*f)(JSON)) | @@ -100,7 +100,7 @@ Handlers::bindJSON(void (Handlers::*f)(JSON)) | ||
| 100 | void | 100 | void |
| 101 | Handlers::initHandlers() | 101 | Handlers::initHandlers() |
| 102 | { | 102 | { |
| 103 | - this->json_handlers.push_back(std::make_shared<JSONHandler>()); | 103 | + this->json_handlers.emplace_back(std::make_shared<JSONHandler>()); |
| 104 | this->jh = this->json_handlers.back().get(); | 104 | this->jh = this->json_handlers.back().get(); |
| 105 | jh->addDictHandlers( | 105 | jh->addDictHandlers( |
| 106 | [](std::string const&, JSON) {}, | 106 | [](std::string const&, JSON) {}, |
| @@ -184,8 +184,9 @@ Handlers::pushKey(std::string const& key) | @@ -184,8 +184,9 @@ Handlers::pushKey(std::string const& key) | ||
| 184 | { | 184 | { |
| 185 | auto new_jh = std::make_shared<JSONHandler>(); | 185 | auto new_jh = std::make_shared<JSONHandler>(); |
| 186 | this->jh->addDictKeyHandler(key, new_jh); | 186 | this->jh->addDictKeyHandler(key, new_jh); |
| 187 | - this->json_handlers.push_back(new_jh); | ||
| 188 | this->jh = new_jh.get(); | 187 | this->jh = new_jh.get(); |
| 188 | + this->json_handlers.emplace_back(std::move(new_jh)); | ||
| 189 | + | ||
| 189 | } | 190 | } |
| 190 | 191 | ||
| 191 | void | 192 | void |
| @@ -205,8 +206,9 @@ Handlers::beginArray(json_handler_t start_fn, bare_handler_t end_fn) | @@ -205,8 +206,9 @@ Handlers::beginArray(json_handler_t start_fn, bare_handler_t end_fn) | ||
| 205 | [end_fn](std::string const&) { end_fn(); }, | 206 | [end_fn](std::string const&) { end_fn(); }, |
| 206 | item_jh); | 207 | item_jh); |
| 207 | jh->addFallbackHandler(item_jh); | 208 | jh->addFallbackHandler(item_jh); |
| 208 | - this->json_handlers.push_back(item_jh); | ||
| 209 | this->jh = item_jh.get(); | 209 | this->jh = item_jh.get(); |
| 210 | + this->json_handlers.emplace_back(std::move(item_jh)); | ||
| 211 | + | ||
| 210 | } | 212 | } |
| 211 | 213 | ||
| 212 | void | 214 | void |