2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-10 23:20:58 +00:00

Tune parsing of dictionaries in QPDFParser::parse

Use move semantics for dictionary creation.
This commit is contained in:
m-holger 2022-12-19 19:20:36 +00:00 committed by Jay Berkenbilt
parent 846504129f
commit d67a54ae93
3 changed files with 17 additions and 1 deletions

View File

@ -404,7 +404,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
QPDFObjectHandle::newString(frame.contents_string); QPDFObjectHandle::newString(frame.contents_string);
dict["/Contents"].setParsedOffset(frame.contents_offset); dict["/Contents"].setParsedOffset(frame.contents_offset);
} }
object = QPDF_Dictionary::create(dict); object = QPDF_Dictionary::create(std::move(dict));
setDescription(object, offset - 2); setDescription(object, offset - 2);
// The `offset` points to the next of "<<". Set the rewind // The `offset` points to the next of "<<". Set the rewind
// offset to point to the beginning of "<<". This has been // offset to point to the beginning of "<<". This has been

View File

@ -9,12 +9,25 @@ QPDF_Dictionary::QPDF_Dictionary(
{ {
} }
QPDF_Dictionary::QPDF_Dictionary(
std::map<std::string, QPDFObjectHandle>&& items) :
QPDFValue(::ot_dictionary, "dictionary"),
items(items)
{
}
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items) QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle> const& items)
{ {
return do_create(new QPDF_Dictionary(items)); return do_create(new QPDF_Dictionary(items));
} }
std::shared_ptr<QPDFObject>
QPDF_Dictionary::create(std::map<std::string, QPDFObjectHandle>&& items)
{
return do_create(new QPDF_Dictionary(items));
}
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Dictionary::copy(bool shallow) QPDF_Dictionary::copy(bool shallow)
{ {

View File

@ -14,6 +14,8 @@ class QPDF_Dictionary: public QPDFValue
virtual ~QPDF_Dictionary() = default; virtual ~QPDF_Dictionary() = default;
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create(std::map<std::string, QPDFObjectHandle> const& items); create(std::map<std::string, QPDFObjectHandle> const& items);
static std::shared_ptr<QPDFObject>
create(std::map<std::string, QPDFObjectHandle>&& items);
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
@ -35,6 +37,7 @@ class QPDF_Dictionary: public QPDFValue
private: private:
QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items); QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items);
QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items);
std::map<std::string, QPDFObjectHandle> items; std::map<std::string, QPDFObjectHandle> items;
}; };