[poppler] 10 commits - poppler/FontInfo.cc poppler/GfxFont.cc poppler/GfxFont.h poppler/GfxState.cc poppler/Link.cc poppler/Object.cc poppler/OptionalContent.cc poppler/OptionalContent.h poppler/StructElement.cc poppler/StructElement.h poppler/StructTreeRoot.cc test/pdf-fullrewrite.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Feb 27 15:23:10 UTC 2019
poppler/FontInfo.cc | 20 ++++++++++----------
poppler/GfxFont.cc | 7 +++----
poppler/GfxFont.h | 4 ++--
poppler/GfxState.cc | 6 +++---
poppler/Link.cc | 14 +++++++-------
poppler/Object.cc | 5 ++---
poppler/OptionalContent.cc | 26 +++++++++++++-------------
poppler/OptionalContent.h | 6 +++---
poppler/StructElement.cc | 4 ++--
poppler/StructElement.h | 4 ++--
poppler/StructTreeRoot.cc | 18 +++++++++---------
test/pdf-fullrewrite.cc | 12 ++++++------
12 files changed, 62 insertions(+), 64 deletions(-)
New commits:
commit 099a09c57224a8072d1591c193815e6434178f25
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:58:42 2019 +0100
pdf-fullrewrite: Save copy() calls
diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index d9b8ac3e..22b76a3f 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -16,7 +16,7 @@
#include "utils/parseargs.h"
static bool compareDocuments(PDFDoc *origDoc, PDFDoc *newDoc);
-static bool compareObjects(Object *objA, Object *objB);
+static bool compareObjects(const Object *objA, const Object *objB);
static char ownerPassword[33] = "\001";
static char userPassword[33] = "\001";
@@ -125,8 +125,8 @@ static bool compareDictionaries(Dict *dictA, Dict *dictB)
* in dictB is also contained in dictA */
for (int i = 0; i < length; ++i) {
const char *key = dictA->getKey(i);
- Object valA = dictA->getValNF(i).copy();
- Object valB = dictB->lookupNF(key).copy();
+ const Object &valA = dictA->getValNF(i);
+ const Object &valB = dictB->lookupNF(key);
if (!compareObjects(&valA, &valB))
return false;
}
@@ -134,7 +134,7 @@ static bool compareDictionaries(Dict *dictA, Dict *dictB)
return true;
}
-static bool compareObjects(Object *objA, Object *objB)
+static bool compareObjects(const Object *objA, const Object *objB)
{
switch (objA->getType()) {
case objBool:
@@ -197,8 +197,8 @@ static bool compareObjects(Object *objA, Object *objB)
return false;
} else {
for (int i = 0; i < length; ++i) {
- Object elemA = arrayA->getNF(i).copy();
- Object elemB = arrayB->getNF(i).copy();
+ const Object &elemA = arrayA->getNF(i);
+ const Object &elemB = arrayB->getNF(i);
if (!compareObjects(&elemA, &elemB)) {
return false;
}
commit 1005f8ab69ef539bc46ad3fd4d7e610de0204239
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:56:23 2019 +0100
StructTreeRoot::parseNumberTreeNode: Save copy() call
diff --git a/poppler/StructTreeRoot.cc b/poppler/StructTreeRoot.cc
index 099bf62f..99359b76 100644
--- a/poppler/StructTreeRoot.cc
+++ b/poppler/StructTreeRoot.cc
@@ -141,11 +141,11 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
int keyVal = key.getInt();
std::vector<Parent>& vec = parentTree[keyVal];
- Object value = nums.arrayGet(i + 1);
- if (value.isArray()) {
- vec.resize(value.arrayGetLength());
- for (int j = 0; j < value.arrayGetLength(); j++) {
- const Object &itemvalue = value.arrayGetNF(j);
+ Object valueArray = nums.arrayGet(i + 1);
+ if (valueArray.isArray()) {
+ vec.resize(valueArray.arrayGetLength());
+ for (int j = 0; j < valueArray.arrayGetLength(); j++) {
+ const Object &itemvalue = valueArray.arrayGetNF(j);
if (itemvalue.isRef()) {
Ref ref = itemvalue.getRef();
vec[j].ref = ref;
@@ -155,14 +155,14 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
}
}
} else {
- value = nums.arrayGetNF(i + 1).copy();
- if (value.isRef()) {
- Ref ref = value.getRef();
+ const Object &valueRef = nums.arrayGetNF(i + 1);
+ if (valueRef.isRef()) {
+ Ref ref = valueRef.getRef();
vec.resize(1);
vec[0].ref = ref;
refToParentMap.insert(std::pair<Ref, Parent*>(ref, &vec[0]));
} else {
- error(errSyntaxError, -1, "Nums item at position {0:d} is wrong type ({1:s})", i + 1, value.getTypeName());
+ error(errSyntaxError, -1, "Nums item at position {0:d} is wrong type ({1:s})", i + 1, valueRef.getTypeName());
}
}
}
commit 6b099768fad76d06a7351fc2a446859cfce983fb
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:54:30 2019 +0100
StructElement::parseChild: Save copy() call
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index 250a1d38..3cde8c91 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -1177,7 +1177,7 @@ void StructElement::parse(Dict *element)
}
}
-StructElement *StructElement::parseChild(Object *ref,
+StructElement *StructElement::parseChild(const Object *ref,
Object *childObj,
std::set<int> &seen)
{
@@ -1255,7 +1255,7 @@ void StructElement::parseChildren(Dict *element, std::set<int> &seen)
if (kids.isArray()) {
for (int i = 0; i < kids.arrayGetLength(); i++) {
Object obj = kids.arrayGet(i);
- Object ref = kids.arrayGetNF(i).copy();
+ const Object &ref = kids.arrayGetNF(i);
parseChild(&ref, &obj, seen);
}
} else if (kids.isDict() || kids.isInt()) {
diff --git a/poppler/StructElement.h b/poppler/StructElement.h
index 7c232a94..b654366d 100644
--- a/poppler/StructElement.h
+++ b/poppler/StructElement.h
@@ -6,7 +6,7 @@
//
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Luigi Scarso <luigi.scarso at gmail.com>
-// Copyright 2014, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2014, 2018, 2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2018 Adam Reichold <adam.reichold at t-online.de>
//
//========================================================================
@@ -298,7 +298,7 @@ private:
StructElement(const Ref ref, StructTreeRoot *treeRootA, StructElement *parentA);
void parse(Dict* elementDict);
- StructElement* parseChild(Object *ref, Object* childObj, std::set<int> &seen);
+ StructElement* parseChild(const Object *ref, Object* childObj, std::set<int> &seen);
void parseChildren(Dict* element, std::set<int> &seen);
void parseAttributes(Dict *element, bool keepExisting = false);
commit 2c26b40b8fd82f813c7a8f115ecfa12096452849
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:52:51 2019 +0100
OptionalContent: Save unneeded copy() calls
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index 7a5db5c2..f4906bf9 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -46,19 +46,19 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
// we now enumerate over the ocgList, and build up the optionalContentGroups list.
for(int i = 0; i < ocgList.arrayGetLength(); ++i) {
- Object ocg = ocgList.arrayGet(i);
- if (!ocg.isDict()) {
+ Object ocgDict = ocgList.arrayGet(i);
+ if (!ocgDict.isDict()) {
break;
}
- auto thisOptionalContentGroup = std::make_unique<OptionalContentGroup>(ocg.getDict());
- ocg = ocgList.arrayGetNF(i).copy();
- if (!ocg.isRef()) {
+ auto thisOptionalContentGroup = std::make_unique<OptionalContentGroup>(ocgDict.getDict());
+ const Object &ocgRef = ocgList.arrayGetNF(i);
+ if (!ocgRef.isRef()) {
break;
}
- thisOptionalContentGroup->setRef( ocg.getRef() );
+ thisOptionalContentGroup->setRef( ocgRef.getRef() );
// the default is ON - we change state later, depending on BaseState, ON and OFF
thisOptionalContentGroup->setState(OptionalContentGroup::On);
- optionalContentGroups.emplace(ocg.getRef(), std::move(thisOptionalContentGroup));
+ optionalContentGroups.emplace(ocgRef.getRef(), std::move(thisOptionalContentGroup));
}
Object defaultOcgConfig = ocgObject->dictLookup("D");
@@ -367,7 +367,7 @@ OptionalContentGroup::~OptionalContentGroup()
//------------------------------------------------------------------------
-OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
+OCDisplayNode *OCDisplayNode::parse(const Object *obj, OCGs *oc,
XRef *xref, int recursion) {
OptionalContentGroup *ocgA;
OCDisplayNode *node, *child;
@@ -399,7 +399,7 @@ OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
node = new OCDisplayNode();
}
for (; i < obj2.arrayGetLength(); ++i) {
- Object obj3 = obj2.arrayGetNF(i).copy();
+ const Object &obj3 = obj2.arrayGetNF(i);
if ((child = OCDisplayNode::parse(&obj3, oc, xref, recursion + 1))) {
if (!child->ocg && !child->name && node->getNumChildren() > 0) {
node->getChild(node->getNumChildren() - 1)->addChildren(child->takeChildren());
diff --git a/poppler/OptionalContent.h b/poppler/OptionalContent.h
index f9c5260e..e4144e64 100644
--- a/poppler/OptionalContent.h
+++ b/poppler/OptionalContent.h
@@ -118,7 +118,7 @@ private:
class OCDisplayNode {
public:
- static OCDisplayNode *parse(Object *obj, OCGs *oc, XRef *xref, int recursion = 0);
+ static OCDisplayNode *parse(const Object *obj, OCGs *oc, XRef *xref, int recursion = 0);
OCDisplayNode();
~OCDisplayNode();
commit b7de46a75644d9e7289c7ec1972ccc6c4eb5afa5
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:49:47 2019 +0100
Object::print: Save unneded copy() calls
diff --git a/poppler/Object.cc b/poppler/Object.cc
index be53947a..85398b22 100644
--- a/poppler/Object.cc
+++ b/poppler/Object.cc
@@ -127,7 +127,6 @@ const char *Object::getTypeName() const {
}
void Object::print(FILE *f) const {
- Object obj;
int i;
switch (type) {
@@ -156,7 +155,7 @@ void Object::print(FILE *f) const {
for (i = 0; i < arrayGetLength(); ++i) {
if (i > 0)
fprintf(f, " ");
- obj = arrayGetNF(i).copy();
+ const Object &obj = arrayGetNF(i);
obj.print(f);
}
fprintf(f, "]");
@@ -165,7 +164,7 @@ void Object::print(FILE *f) const {
fprintf(f, "<<");
for (i = 0; i < dictGetLength(); ++i) {
fprintf(f, " /%s ", dictGetKey(i));
- obj = dictGetValNF(i).copy();
+ const Object &obj = dictGetValNF(i);
obj.print(f);
}
fprintf(f, " >>");
commit 8b8c9ea6eb89bc6b6a0fb0d479e58ba55345e574
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:48:54 2019 +0100
LinkDest::LinkDest: Save unneeded copy() call
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 525c4423..32fc41cd 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -230,13 +230,13 @@ LinkDest::LinkDest(const Array *a) {
error(errSyntaxWarning, -1, "Annotation destination array is too short");
return;
}
- Object obj1 = a->getNF(0).copy();
- if (obj1.isInt()) {
- pageNum = obj1.getInt() + 1;
+ const Object &obj0 = a->getNF(0);
+ if (obj0.isInt()) {
+ pageNum = obj0.getInt() + 1;
pageIsRef = false;
- } else if (obj1.isRef()) {
- pageRef.num = obj1.getRefNum();
- pageRef.gen = obj1.getRefGen();
+ } else if (obj0.isRef()) {
+ pageRef.num = obj0.getRefNum();
+ pageRef.gen = obj0.getRefGen();
pageIsRef = true;
} else {
error(errSyntaxWarning, -1, "Bad annotation destination");
@@ -244,7 +244,7 @@ LinkDest::LinkDest(const Array *a) {
}
// get destination type
- obj1 = a->get(1);
+ Object obj1 = a->get(1);
// XYZ link
if (obj1.isName("XYZ")) {
commit 8579a7b95b6658d1e1a905a8e0ec938f42b8b8f0
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:48:38 2019 +0100
GfxICCBasedColorSpace::parse: Save unneeded copy() call
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index f0ea0257..300f1f2b 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -1828,9 +1828,9 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState
error(errSyntaxError, -1, "Bad ICCBased color space");
return nullptr;
}
- obj1 = arr->getNF(1).copy();
- if (obj1.isRef()) {
- iccProfileStreamA = obj1.getRef();
+ const Object &obj1Ref = arr->getNF(1);
+ if (obj1Ref.isRef()) {
+ iccProfileStreamA = obj1Ref.getRef();
} else {
iccProfileStreamA.num = 0;
iccProfileStreamA.gen = 0;
commit 4b00c90dcfb2283d872c0dc07d7a54ebd490aaf8
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 15:14:19 2019 +0100
GfxFontDict::hashFontObject1: Remove unnecessary copy calls
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 014e5caa..172d8375 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -2479,8 +2479,7 @@ int GfxFontDict::hashFontObject(Object *obj) {
return h.get31();
}
-void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
- Object obj2;
+void GfxFontDict::hashFontObject1(const Object *obj, FNVHash *h) {
const GooString *s;
const char *p;
double r;
@@ -2519,7 +2518,7 @@ void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
n = obj->arrayGetLength();
h->hash((char *)&n, sizeof(int));
for (i = 0; i < n; ++i) {
- obj2 = obj->arrayGetNF(i).copy();
+ const Object &obj2 = obj->arrayGetNF(i);
hashFontObject1(&obj2, h);
}
break;
@@ -2530,7 +2529,7 @@ void GfxFontDict::hashFontObject1(Object *obj, FNVHash *h) {
for (i = 0; i < n; ++i) {
p = obj->dictGetKey(i);
h->hash(p, (int)strlen(p));
- obj2 = obj->dictGetValNF(i).copy();
+ const Object &obj2 = obj->dictGetValNF(i);
hashFontObject1(&obj2, h);
}
break;
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index de99e298..0b1b03e3 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2005, 2008, 2015, 2017, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2008, 2015, 2017-2019 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2006 Takashi Iwai <tiwai at suse.de>
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
@@ -456,7 +456,7 @@ public:
private:
int hashFontObject(Object *obj);
- void hashFontObject1(Object *obj, FNVHash *h);
+ void hashFontObject1(const Object *obj, FNVHash *h);
GfxFont **fonts; // list of fonts
int numFonts; // number of fonts
commit 063eda5fae00bfb62f04941dc0657596f67683db
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 14:59:46 2019 +0100
OptionalContent: Remove some unnecessary copy()
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index 75b93f4c..7a5db5c2 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -194,7 +194,7 @@ bool OCGs::optContentIsVisible( Object *dictRef )
return result;
}
-bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
+bool OCGs::evalOCVisibilityExpr(const Object *expr, int recursion) {
OptionalContentGroup *ocg;
bool ret;
@@ -217,7 +217,7 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
Object op = expr2.arrayGet(0);
if (op.isName("Not")) {
if (expr2.arrayGetLength() == 2) {
- Object obj = expr2.arrayGetNF(1).copy();
+ const Object &obj = expr2.arrayGetNF(1);
ret = !evalOCVisibilityExpr(&obj, recursion + 1);
} else {
error(errSyntaxError, -1,
@@ -227,13 +227,13 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
} else if (op.isName("And")) {
ret = true;
for (int i = 1; i < expr2.arrayGetLength() && ret; ++i) {
- Object obj = expr2.arrayGetNF(i).copy();
+ const Object &obj = expr2.arrayGetNF(i);
ret = evalOCVisibilityExpr(&obj, recursion + 1);
}
} else if (op.isName("Or")) {
ret = false;
for (int i = 1; i < expr2.arrayGetLength() && !ret; ++i) {
- Object obj = expr2.arrayGetNF(i).copy();
+ const Object &obj = expr2.arrayGetNF(i);
ret = evalOCVisibilityExpr(&obj, recursion + 1);
}
} else {
diff --git a/poppler/OptionalContent.h b/poppler/OptionalContent.h
index c383262c..f9c5260e 100644
--- a/poppler/OptionalContent.h
+++ b/poppler/OptionalContent.h
@@ -4,7 +4,7 @@
//
// Copyright 2007 Brad Hards <bradh at kde.org>
// Copyright 2008 Carlos Garcia Campos <carlosgc at gnome.org>
-// Copyright 2013, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2013, 2018, 2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2018 Adam Reichold <adam.reichold at t-online.de>
//
// Released under the GPL (version 2, or later, at your option)
@@ -58,7 +58,7 @@ public:
private:
bool ok;
- bool evalOCVisibilityExpr(Object *expr, int recursion);
+ bool evalOCVisibilityExpr(const Object *expr, int recursion);
bool allOn( Array *ocgArray );
bool allOff( Array *ocgArray );
bool anyOn( Array *ocgArray );
commit 32c7d7437974a8b675b9e4913de9d35a100888ea
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Feb 27 14:57:03 2019 +0100
FontInfoScanner::scanFonts: remove unnecessary Object::copy
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 9ce4ce3e..8467d650 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -99,15 +99,15 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList)
// scan the fonts in this resource dictionary
gfxFontDict = nullptr;
- Object obj1 = resDict->lookupNF("Font");
- if (obj1.isRef()) {
- Object obj2 = obj1.fetch(xrefA);
+ Object fontObj = resDict->lookupNF("Font");
+ if (fontObj.isRef()) {
+ Object obj2 = fontObj.fetch(xrefA);
if (obj2.isDict()) {
- Ref r = obj1.getRef();
+ Ref r = fontObj.getRef();
gfxFontDict = new GfxFontDict(xrefA, &r, obj2.getDict());
}
- } else if (obj1.isDict()) {
- gfxFontDict = new GfxFontDict(xrefA, nullptr, obj1.getDict());
+ } else if (fontObj.isDict()) {
+ gfxFontDict = new GfxFontDict(xrefA, nullptr, fontObj.getDict());
}
if (gfxFontDict) {
for (int i = 0; i < gfxFontDict->getNumFonts(); ++i) {
@@ -131,10 +131,10 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList)
Object objDict = resDict->lookup(resTypes[resType]);
if (objDict.isDict()) {
for (int i = 0; i < objDict.dictGetLength(); ++i) {
- obj1 = objDict.dictGetValNF(i).copy();
- if (obj1.isRef()) {
+ const Object &resObj = objDict.dictGetValNF(i).copy();
+ if (resObj.isRef()) {
// check for an already-seen object
- const Ref r = obj1.getRef();
+ const Ref r = resObj.getRef();
if (visitedObjects.find(r.num) != visitedObjects.end()) {
continue;
}
@@ -142,7 +142,7 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList)
visitedObjects.insert(r.num);
}
- Object obj2 = obj1.fetch(xrefA);
+ Object obj2 = resObj.fetch(xrefA);
if (obj2.isStream()) {
Object resObj = obj2.streamGetDict()->lookup("Resources");
if (resObj.isDict() && resObj.getDict() != resDict) {
More information about the poppler
mailing list