Commit d67a54ae93640f784a03df5d07404df13b1b297a
Committed by
Jay Berkenbilt
1 parent
84650412
Tune parsing of dictionaries in QPDFParser::parse
Use move semantics for dictionary creation.
Showing
3 changed files
with
17 additions
and
1 deletions
libqpdf/QPDFParser.cc
| @@ -404,7 +404,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | @@ -404,7 +404,7 @@ QPDFParser::parse(bool& empty, bool content_stream) | ||
| 404 | QPDFObjectHandle::newString(frame.contents_string); | 404 | QPDFObjectHandle::newString(frame.contents_string); |
| 405 | dict["/Contents"].setParsedOffset(frame.contents_offset); | 405 | dict["/Contents"].setParsedOffset(frame.contents_offset); |
| 406 | } | 406 | } |
| 407 | - object = QPDF_Dictionary::create(dict); | 407 | + object = QPDF_Dictionary::create(std::move(dict)); |
| 408 | setDescription(object, offset - 2); | 408 | setDescription(object, offset - 2); |
| 409 | // The `offset` points to the next of "<<". Set the rewind | 409 | // The `offset` points to the next of "<<". Set the rewind |
| 410 | // offset to point to the beginning of "<<". This has been | 410 | // offset to point to the beginning of "<<". This has been |
libqpdf/QPDF_Dictionary.cc
| @@ -9,6 +9,13 @@ QPDF_Dictionary::QPDF_Dictionary( | @@ -9,6 +9,13 @@ QPDF_Dictionary::QPDF_Dictionary( | ||
| 9 | { | 9 | { |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | +QPDF_Dictionary::QPDF_Dictionary( | ||
| 13 | + std::map<std::string, QPDFObjectHandle>&& items) : | ||
| 14 | + QPDFValue(::ot_dictionary, "dictionary"), | ||
| 15 | + items(items) | ||
| 16 | +{ | ||
| 17 | +} | ||
| 18 | + | ||
| 12 | std::shared_ptr<QPDFObject> | 19 | std::shared_ptr<QPDFObject> |
| 13 | QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items) | 20 | QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items) |
| 14 | { | 21 | { |
| @@ -16,6 +23,12 @@ QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items) | @@ -16,6 +23,12 @@ QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items) | ||
| 16 | } | 23 | } |
| 17 | 24 | ||
| 18 | std::shared_ptr<QPDFObject> | 25 | std::shared_ptr<QPDFObject> |
| 26 | +QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle>&& items) | ||
| 27 | +{ | ||
| 28 | + return do_create(new QPDF_Dictionary(items)); | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +std::shared_ptr<QPDFObject> | ||
| 19 | QPDF_Dictionary::copy(bool shallow) | 32 | QPDF_Dictionary::copy(bool shallow) |
| 20 | { | 33 | { |
| 21 | if (shallow) { | 34 | if (shallow) { |
libqpdf/qpdf/QPDF_Dictionary.hh
| @@ -14,6 +14,8 @@ class QPDF_Dictionary: public QPDFValue | @@ -14,6 +14,8 @@ class QPDF_Dictionary: public QPDFValue | ||
| 14 | virtual ~QPDF_Dictionary() = default; | 14 | virtual ~QPDF_Dictionary() = default; |
| 15 | static std::shared_ptr<QPDFObject> | 15 | static std::shared_ptr<QPDFObject> |
| 16 | create(std::map<std::string, QPDFObjectHandle> const& items); | 16 | create(std::map<std::string, QPDFObjectHandle> const& items); |
| 17 | + static std::shared_ptr<QPDFObject> | ||
| 18 | + create(std::map<std::string, QPDFObjectHandle>&& items); | ||
| 17 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 19 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 18 | virtual std::string unparse(); | 20 | virtual std::string unparse(); |
| 19 | virtual JSON getJSON(int json_version); | 21 | virtual JSON getJSON(int json_version); |
| @@ -35,6 +37,7 @@ class QPDF_Dictionary: public QPDFValue | @@ -35,6 +37,7 @@ class QPDF_Dictionary: public QPDFValue | ||
| 35 | 37 | ||
| 36 | private: | 38 | private: |
| 37 | QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items); | 39 | QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items); |
| 40 | + QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items); | ||
| 38 | std::map<std::string, QPDFObjectHandle> items; | 41 | std::map<std::string, QPDFObjectHandle> items; |
| 39 | }; | 42 | }; |
| 40 | 43 |