Commit 647a9813 authored by Albert Astals Cid's avatar Albert Astals Cid

Save Object::copy on Page construction

parent 8f158da9
......@@ -293,7 +293,7 @@ bool Catalog::cachePageTree(int page)
Object kid = kids.arrayGet(kidsIdx);
if (kid.isDict("Page") || (kid.isDict() && !kid.getDict()->hasKey("Kids"))) {
PageAttrs *attrs = new PageAttrs(attrsList->back(), kid.getDict());
auto p = std::make_unique<Page>(doc, pages.size()+1, &kid,
auto p = std::make_unique<Page>(doc, pages.size()+1, std::move(kid),
kidRef.getRef(), attrs, form);
if (!p->isOk()) {
error(errSyntaxError, -1, "Failed to create page (page {0:uld})", pages.size()+1);
......@@ -739,7 +739,7 @@ int Catalog::getNumPages()
Dict *pageDict = pagesDict.getDict();
if (pageRootRef.isRef()) {
const Ref pageRef = pageRootRef.getRef();
auto p = std::make_unique<Page>(doc, 1, &pagesDict, pageRef, new PageAttrs(nullptr, pageDict), form);
auto p = std::make_unique<Page>(doc, 1, std::move(pagesDict), pageRef, new PageAttrs(nullptr, pageDict), form);
if (p->isOk()) {
pages.emplace_back(std::move(p), pageRef);
......
......@@ -2099,7 +2099,7 @@ Page *PDFDoc::parsePage(int page)
}
Dict *pageDict = obj.getDict();
return new Page(this, page, &obj, pageRef,
return new Page(this, page, std::move(obj), pageRef,
new PageAttrs(nullptr, pageDict), catalog->getForm());
}
......
......@@ -242,7 +242,7 @@ bool PageAttrs::readBox(Dict *dict, const char *key, PDFRectangle *box) {
#define pageLocker() std::unique_lock<std::recursive_mutex> locker(mutex)
Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form) {
ok = true;
doc = docA;
xref = doc->getXRef();
......@@ -250,7 +250,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
duration = -1;
annots = nullptr;
pageObj = pageDict->copy();
pageObj = std::move(pageDict);
pageRef = pageRefA;
// get attributes
......@@ -258,7 +258,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
attrs->clipBoxes();
// transtion
trans = pageDict->dictLookupNF("Trans");
trans = pageObj.dictLookupNF("Trans");
if (!(trans.isRef() || trans.isDict() || trans.isNull())) {
error(errSyntaxError, -1, "Page transition object (page {0:d}) is wrong type ({1:s})",
num, trans.getTypeName());
......@@ -266,7 +266,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
}
// duration
Object tmp = pageDict->dictLookupNF("Dur");
Object tmp = pageObj.dictLookupNF("Dur");
if (!(tmp.isNum() || tmp.isNull())) {
error(errSyntaxError, -1, "Page duration object (page {0:d}) is wrong type ({1:s})",
num, tmp.getTypeName());
......@@ -275,7 +275,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
}
// annotations
annotsObj = pageDict->dictLookupNF("Annots");
annotsObj = pageObj.dictLookupNF("Annots");
if (!(annotsObj.isRef() || annotsObj.isArray() || annotsObj.isNull())) {
error(errSyntaxError, -1, "Page annotations object (page {0:d}) is wrong type ({1:s})",
num, annotsObj.getTypeName());
......@@ -283,7 +283,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
}
// contents
contents = pageDict->dictLookupNF("Contents");
contents = pageObj.dictLookupNF("Contents");
if (!(contents.isRef() || contents.isArray() ||
contents.isNull())) {
error(errSyntaxError, -1, "Page contents object (page {0:d}) is wrong type ({1:s})",
......@@ -292,7 +292,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
}
// thumb
thumb = pageDict->dictLookupNF("Thumb");
thumb = pageObj.dictLookupNF("Thumb");
if (!(thumb.isStream() || thumb.isNull() || thumb.isRef())) {
error(errSyntaxError, -1, "Page thumb object (page {0:d}) is wrong type ({1:s})",
num, thumb.getTypeName());
......@@ -300,7 +300,7 @@ Page::Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *at
}
// actions
actions = pageDict->dictLookupNF("AA");
actions = pageObj.dictLookupNF("AA");
if (!(actions.isDict() || actions.isNull())) {
error(errSyntaxError, -1, "Page additional action object (page {0:d}) is wrong type ({1:s})",
num, actions.getTypeName());
......
......@@ -141,7 +141,7 @@ class Page {
public:
// Constructor.
Page(PDFDoc *docA, int numA, Object *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
// Destructor.
~Page();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment