Commit d67a54ae93640f784a03df5d07404df13b1b297a

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 84650412

Tune parsing of dictionaries in QPDFParser::parse

Use move semantics for dictionary creation.
libqpdf/QPDFParser.cc
... ... @@ -404,7 +404,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
404 404 QPDFObjectHandle::newString(frame.contents_string);
405 405 dict["/Contents"].setParsedOffset(frame.contents_offset);
406 406 }
407   - object = QPDF_Dictionary::create(dict);
  407 + object = QPDF_Dictionary::create(std::move(dict));
408 408 setDescription(object, offset - 2);
409 409 // The `offset` points to the next of "<<". Set the rewind
410 410 // offset to point to the beginning of "<<". This has been
... ...
libqpdf/QPDF_Dictionary.cc
... ... @@ -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 19 std::shared_ptr<QPDFObject>
13 20 QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items)
14 21 {
... ... @@ -16,6 +23,12 @@ QPDF_Dictionary::create(std::map&lt;std::string, QPDFObjectHandle&gt; const&amp; items)
16 23 }
17 24  
18 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 32 QPDF_Dictionary::copy(bool shallow)
20 33 {
21 34 if (shallow) {
... ...
libqpdf/qpdf/QPDF_Dictionary.hh
... ... @@ -14,6 +14,8 @@ class QPDF_Dictionary: public QPDFValue
14 14 virtual ~QPDF_Dictionary() = default;
15 15 static std::shared_ptr<QPDFObject>
16 16 create(std::map<std::string, QPDFObjectHandle> const& items);
  17 + static std::shared_ptr<QPDFObject>
  18 + create(std::map<std::string, QPDFObjectHandle>&& items);
17 19 virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
18 20 virtual std::string unparse();
19 21 virtual JSON getJSON(int json_version);
... ... @@ -35,6 +37,7 @@ class QPDF_Dictionary: public QPDFValue
35 37  
36 38 private:
37 39 QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items);
  40 + QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items);
38 41 std::map<std::string, QPDFObjectHandle> items;
39 42 };
40 43  
... ...