Commit 597e26e9 authored by Albert Astals Cid's avatar Albert Astals Cid

Make Annot::getNF and Dict::getNF return const & instead of copy

Lots of users can deal with a const & directly, so it saves us some
copying. For the ones that can't move the copy to the caller side.

Some of copy() on the caller side can be easily removed, that will come
on next commits
parent 0a4e86e8
......@@ -2845,7 +2845,7 @@ get_optional_content_rbgroups (OCGs *ocg)
for (j = 0; j < rb_array->getLength (); ++j) {
OptionalContentGroup *oc;
Object ref = rb_array->getNF (j);
const Object &ref = rb_array->getNF (j);
if (!ref.isRef ()) {
continue;
}
......@@ -2888,7 +2888,7 @@ get_optional_content_items_sorted (OCGs *ocg, Layer *parent, Array *order)
Object orderItem = order->get (i);
if (orderItem.isDict ()) {
Object ref = order->getNF (i);
const Object &ref = order->getNF (i);
if (ref.isRef ()) {
OptionalContentGroup *oc = ocg->findOcgByRef (ref.getRef ());
Layer *layer = layer_new (oc);
......
......@@ -938,7 +938,7 @@ bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) {
} else if (stateObj->isDict()) { // Test each value
const int size = stateObj->dictGetLength();
for (int i = 0; i < size; ++i) {
Object obj1 = stateObj->dictGetValNF(i);
const Object &obj1 = stateObj->dictGetValNF(i);
if (obj1.isRef()) {
Ref r = obj1.getRef();
if (r.num == refToStream.num && r.gen == refToStream.gen) {
......@@ -1001,7 +1001,7 @@ void AnnotAppearance::removeStateStreams(Object *obj1) {
} else if (obj1->isDict()) {
const int size = obj1->dictGetLength();
for (int i = 0; i < size; ++i) {
Object obj2 = obj1->dictGetValNF(i);
const Object &obj2 = obj1->dictGetValNF(i);
if (obj2.isRef()) {
removeStream(obj2.getRef());
}
......@@ -6646,7 +6646,7 @@ Annots::Annots(PDFDoc *docA, int page, Object *annotsObj) {
//form widget
Object obj1 = annotsObj->arrayGet(i);
if (obj1.isDict()) {
Object obj2 = annotsObj->arrayGetNF(i);
const Object &obj2 = annotsObj->arrayGetNF(i);
annot = createAnnot (std::move(obj1), &obj2);
if (annot) {
if (annot->isOk()) {
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2013, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2013, 2017, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
......@@ -77,16 +77,17 @@ Object Array::get(int i, int recursion) const {
return elems[i].fetch(xref, recursion);
}
Object Array::getNF(int i) const {
const Object &Array::getNF(int i) const {
if (i < 0 || std::size_t(i) >= elems.size()) {
return Object(objNull);
static Object nullObj(objNull);
return nullObj;
}
return elems[i].copy();
return elems[i];
}
bool Array::getString(int i, GooString *string) const
{
Object obj = getNF(i);
const Object &obj = getNF(i);
if (obj.isString()) {
string->clear();
string->append(obj.getString());
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
......@@ -68,7 +68,7 @@ public:
// Accessors.
Object get(int i, int recursion = 0) const;
Object getNF(int i) const;
const Object &getNF(int i) const;
bool getString(int i, GooString *string) const;
private:
......
......@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2005-2013, 2015, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005-2013, 2015, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005 Jeff Muizelaar <jrmuizel@nit.ca>
// Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
......@@ -270,7 +270,7 @@ bool Catalog::cachePageTree(int page)
continue;
}
Object kidRef = kids.arrayGetNF(kidsIdx);
const Object &kidRef = kids.arrayGetNF(kidsIdx);
if (!kidRef.isRef()) {
error(errSyntaxError, -1, "Kid object (page {0:uld}) is not an indirect reference ({1:s})",
pages.size()+1, kidRef.getTypeName());
......@@ -558,7 +558,7 @@ NameTree::Entry::Entry(Array *array, int index) {
else
error(errSyntaxError, -1, "Invalid page tree");
}
value = array->getNF(index + 1);
value = array->getNF(index + 1).copy();
}
NameTree::Entry::~Entry() {
......@@ -615,7 +615,7 @@ void NameTree::parse(Object *tree, std::set<int> &seen) {
Object kids = tree->dictLookup("Kids");
if (kids.isArray()) {
for (int i = 0; i < kids.arrayGetLength(); ++i) {
Object kidRef = kids.arrayGetNF(i);
const Object &kidRef = kids.arrayGetNF(i);
if (kidRef.isRef()) {
const int numObj = kidRef.getRef().num;
if (seen.find(numObj) != seen.end()) {
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2007-2008 Julien Rebetez <julienr@svn.gnome.org>
// Copyright (C) 2010, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Paweł Wiejacha <pawel.wiejacha@gmail.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
......@@ -82,7 +82,7 @@ public:
// Iterative accessors.
const char *getKey(int i) const { return entries[i].first.c_str(); }
Object getVal(int i) const { return entries[i].second.fetch(xref); }
Object getValNF(int i) const { return entries[i].second.copy(); }
const Object &getValNF(int i) const { return entries[i].second; }
// Set the xref pointer. This is only used in one special case: the
// trailer dictionary, which is read before the xref table is
......
......@@ -131,7 +131,7 @@ 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);
obj1 = objDict.dictGetValNF(i).copy();
if (obj1.isRef()) {
// check for an already-seen object
const Ref r = obj1.getRef();
......
......@@ -634,7 +634,7 @@ FormField::FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *par
if (obj1.isArray()) {
// Load children
for (int i = 0 ; i < obj1.arrayGetLength(); i++) {
Object childRef = obj1.arrayGetNF(i);
const Object &childRef = obj1.arrayGetNF(i);
if (!childRef.isRef()) {
error (errSyntaxError, -1, "Invalid form field renference");
continue;
......@@ -1817,7 +1817,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
Array *array = obj1.getArray();
for(int i=0; i<array->getLength(); i++) {
Object obj2 = array->get(i);
Object oref = array->getNF(i);
const Object &oref = array->getNF(i);
if (!oref.isRef()) {
error(errSyntaxWarning, -1, "Direct object in rootFields");
continue;
......@@ -1846,7 +1846,7 @@ Form::Form(PDFDoc *docA, Object* acroFormA)
Array *array = obj1.getArray();
calculateOrder.reserve(array->getLength());
for(int i=0; i<array->getLength(); i++) {
Object oref = array->getNF(i);
const Object &oref = array->getNF(i);
if (!oref.isRef()) {
error(errSyntaxWarning, -1, "Direct object in CO");
continue;
......
......@@ -690,7 +690,7 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict, std::set<int>
}
for (i = 0; i < k; ++i) {
std::set<int> usedParentsAux = *usedParents;
Object obj2 = obj1.arrayGetNF(i);
Object obj2 = obj1.arrayGetNF(i).copy();
if (obj2.isRef()) {
const Ref ref = obj2.getRef();
if (usedParentsAux.find(ref.num) == usedParentsAux.end()) {
......
......@@ -1241,7 +1241,7 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
if (obj2.isArray()) {
GfxFont *font;
if (obj2.arrayGetLength() == 2) {
Object fargs0 = obj2.arrayGetNF(0);
const Object &fargs0 = obj2.arrayGetNF(0);
Object fargs1 = obj2.arrayGet(1);
if (fargs0.isRef() && fargs1.isNum()) {
Object fobj = fargs0.fetch(xref);
......@@ -1277,7 +1277,7 @@ void Gfx::opSetExtGState(Object args[], int numArgs) {
if (obj2.arrayGetLength() == 2) {
Object dargs[2];
dargs[0] = obj2.arrayGetNF(0);
dargs[0] = obj2.arrayGetNF(0).copy();
dargs[1] = obj2.arrayGet(1);
if (dargs[0].isArray() && dargs[1].isInt()) {
opSetDash(dargs,2);
......
......@@ -2388,7 +2388,7 @@ GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict) {
numFonts = fontDict->getLength();
fonts = (GfxFont **)gmallocn(numFonts, sizeof(GfxFont *));
for (i = 0; i < numFonts; ++i) {
Object obj1 = fontDict->getValNF(i);
const Object &obj1 = fontDict->getValNF(i);
Object obj2 = obj1.fetch(xref);
if (obj2.isDict()) {
if (obj1.isRef()) {
......@@ -2519,7 +2519,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);
obj2 = obj->arrayGetNF(i).copy();
hashFontObject1(&obj2, h);
}
break;
......@@ -2530,7 +2530,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);
obj2 = obj->dictGetValNF(i).copy();
hashFontObject1(&obj2, h);
}
break;
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2006, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2006-2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009, 2012 Koji Otani <sho@bbr.jp>
// Copyright (C) 2009, 2011-2016 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2009, 2019 Christian Persch <chpe@gnome.org>
......@@ -1828,7 +1828,7 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState
error(errSyntaxError, -1, "Bad ICCBased color space");
return nullptr;
}
obj1 = arr->getNF(1);
obj1 = arr->getNF(1).copy();
if (obj1.isRef()) {
iccProfileStreamA = obj1.getRef();
} else {
......
......@@ -16,7 +16,7 @@
// Copyright (C) 2006, 2008 Pino Toscano <pino@kde.org>
// Copyright (C) 2007, 2010, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
// Copyright (C) 2008-2010, 2012-2014, 2016-2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008-2010, 2012-2014, 2016-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
// Copyright (C) 2009 Ilya Gorenbein <igorenbein@finjan.com>
// Copyright (C) 2012 Tobias Koening <tobias.koenig@kdab.com>
......@@ -188,7 +188,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI,
}
// Similar circle check as above.
const Object obj3Ref = a->getNF(i);
const Object &obj3Ref = a->getNF(i);
if (obj3Ref.isRef()) {
const Ref ref = obj3Ref.getRef();
if (!seenNextActions->insert(ref.num).second) {
......@@ -230,7 +230,7 @@ LinkDest::LinkDest(const Array *a) {
error(errSyntaxWarning, -1, "Annotation destination array is too short");
return;
}
Object obj1 = a->getNF(0);
Object obj1 = a->getNF(0).copy();
if (obj1.isInt()) {
pageNum = obj1.getInt() + 1;
pageIsRef = false;
......@@ -829,7 +829,7 @@ LinkOCGState::LinkOCGState(const Object *obj) {
StateList *stList = nullptr;
for (int i = 0; i < obj1.arrayGetLength(); ++i) {
Object obj2 = obj1.arrayGetNF(i);
const Object &obj2 = obj1.arrayGetNF(i);
if (obj2.isName()) {
if (stList)
stateList->push_back(stList);
......
......@@ -156,7 +156,7 @@ void Object::print(FILE *f) const {
for (i = 0; i < arrayGetLength(); ++i) {
if (i > 0)
fprintf(f, " ");
obj = arrayGetNF(i);
obj = arrayGetNF(i).copy();
obj.print(f);
}
fprintf(f, "]");
......@@ -165,7 +165,7 @@ void Object::print(FILE *f) const {
fprintf(f, "<<");
for (i = 0; i < dictGetLength(); ++i) {
fprintf(f, " /%s ", dictGetKey(i));
obj = dictGetValNF(i);
obj = dictGetValNF(i).copy();
obj.print(f);
}
fprintf(f, " >>");
......
......@@ -270,7 +270,7 @@ public:
void arrayAdd(Object &&elem);
void arrayRemove(int i);
Object arrayGet(int i, int recursion) const;
Object arrayGetNF(int i) const;
const Object &arrayGetNF(int i) const;
// Dict accessors.
int dictGetLength() const;
......@@ -283,7 +283,7 @@ public:
Object dictLookupNF(const char *key) const;
const char *dictGetKey(int i) const;
Object dictGetVal(int i) const;
Object dictGetValNF(int i) const;
const Object &dictGetValNF(int i) const;
// Stream accessors.
bool streamIs(const char *dictType) const;
......@@ -338,7 +338,7 @@ inline void Object::arrayRemove(int i)
inline Object Object::arrayGet(int i, int recursion = 0) const
{ OBJECT_TYPE_CHECK(objArray); return array->get(i, recursion); }
inline Object Object::arrayGetNF(int i) const
inline const Object &Object::arrayGetNF(int i) const
{ OBJECT_TYPE_CHECK(objArray); return array->getNF(i); }
//------------------------------------------------------------------------
......@@ -377,7 +377,7 @@ inline const char *Object::dictGetKey(int i) const
inline Object Object::dictGetVal(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getVal(i); }
inline Object Object::dictGetValNF(int i) const
inline const Object &Object::dictGetValNF(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getValNF(i); }
//------------------------------------------------------------------------
......
......@@ -5,7 +5,7 @@
// Copyright 2007 Brad Hards <bradh@kde.org>
// Copyright 2008 Pino Toscano <pino@kde.org>
// Copyright 2008, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright 2008, 2010, 2011, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright 2008, 2010, 2011, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright 2008 Mark Kaplan <mkaplan@finjan.com>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
//
......@@ -51,7 +51,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
break;
}
auto thisOptionalContentGroup = std::make_unique<OptionalContentGroup>(ocg.getDict());
ocg = ocgList.arrayGetNF(i);
ocg = ocgList.arrayGetNF(i).copy();
if (!ocg.isRef()) {
break;
}
......@@ -79,7 +79,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
if (on.isArray()) {
// ON is an optional element
for (int i = 0; i < on.arrayGetLength(); ++i) {
Object reference = on.arrayGetNF(i);
const Object &reference = on.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
break;
......@@ -97,7 +97,7 @@ OCGs::OCGs(Object *ocgObject, XRef *xref) :
if (off.isArray()) {
// OFF is an optional element
for (int i = 0; i < off.arrayGetLength(); ++i) {
Object reference = off.arrayGetNF(i);
const Object &reference = off.arrayGetNF(i);
if (!reference.isRef()) {
// there can be null entries
break;
......@@ -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);
Object obj = expr2.arrayGetNF(1).copy();
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);
Object obj = expr2.arrayGetNF(i).copy();
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);
Object obj = expr2.arrayGetNF(i).copy();
ret = evalOCVisibilityExpr(&obj, recursion + 1);
}
} else {
......@@ -247,7 +247,7 @@ bool OCGs::evalOCVisibilityExpr(Object *expr, int recursion) {
bool OCGs::allOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
Object ocgItem = ocgArray->getNF(i);
const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
......@@ -261,7 +261,7 @@ bool OCGs::allOn( Array *ocgArray )
bool OCGs::allOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
Object ocgItem = ocgArray->getNF(i);
const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
......@@ -275,7 +275,7 @@ bool OCGs::allOff( Array *ocgArray )
bool OCGs::anyOn( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
Object ocgItem = ocgArray->getNF(i);
const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::On ) {
......@@ -289,7 +289,7 @@ bool OCGs::anyOn( Array *ocgArray )
bool OCGs::anyOff( Array *ocgArray )
{
for (int i = 0; i < ocgArray->getLength(); ++i) {
Object ocgItem = ocgArray->getNF(i);
const Object &ocgItem = ocgArray->getNF(i);
if (ocgItem.isRef()) {
OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );
if ( oc && oc->getState() == OptionalContentGroup::Off ) {
......@@ -399,7 +399,7 @@ OCDisplayNode *OCDisplayNode::parse(Object *obj, OCGs *oc,
node = new OCDisplayNode();
}
for (; i < obj2.arrayGetLength(); ++i) {
Object obj3 = obj2.arrayGetNF(i);
Object obj3 = obj2.arrayGetNF(i).copy();
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());
......
......@@ -975,7 +975,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
strcmp(key, "Pages") != 0)
{
if (j > 0) outStr->printf(" ");
Object value = catDict->getValNF(j);
Object value = catDict->getValNF(j).copy();
outStr->printf("/%s ", key);
writeObject(&value, outStr, getXRef(), 0, nullptr, cryptRC4, 0, 0, 0);
}
......@@ -998,7 +998,7 @@ int PDFDoc::savePageAs(const GooString *name, int pageNo)
for (int n = 0; n < pageDict->getLength(); n++) {
if (n > 0) outStr->printf(" ");
const char *key = pageDict->getKey(n);
Object value = pageDict->getValNF(n);
Object value = pageDict->getValNF(n).copy();
if (strcmp(key, "Parent") == 0) {
outStr->printf("/Parent %d 0 R", rootNum + 1);
} else {
......@@ -1253,7 +1253,7 @@ void PDFDoc::writeDictionnary (Dict* dict, OutStream* outStr, XRef *xRef, unsign
GooString *keyNameToPrint = keyName.sanitizedName(false /* non ps mode */);
outStr->printf("/%s ", keyNameToPrint->c_str());
delete keyNameToPrint;
Object obj1 = dict->getValNF(i);
Object obj1 = dict->getValNF(i).copy();
writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen, alreadyWrittenDicts);
}
outStr->printf(">> ");
......@@ -1403,7 +1403,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, unsigned i
array = obj->getArray();
outStr->printf("[");
for (int i=0; i<array->getLength(); i++) {
Object obj1 = array->getNF(i);
Object obj1 = array->getNF(i).copy();
writeObject(&obj1, outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen);
}
outStr->printf("] ");
......@@ -1673,10 +1673,10 @@ void PDFDoc::markDictionnary (Dict* dict, XRef * xRef, XRef *countRef, unsigned
for (int i=0; i<dict->getLength(); i++) {
const char *key = dict->getKey(i);
if (strcmp(key, "Annots") != 0) {
Object obj1 = dict->getValNF(i);
Object obj1 = dict->getValNF(i).copy();
markObject(&obj1, xRef, countRef, numOffset, oldRefNum, newRefNum, alreadyMarkedDicts);
} else {
Object annotsObj = dict->getValNF(i);
Object annotsObj = dict->getValNF(i).copy();
if (!annotsObj.isNull()) {
markAnnotations(&annotsObj, xRef, countRef, 0, oldRefNum, newRefNum, alreadyMarkedDicts);
}
......@@ -1696,7 +1696,7 @@ void PDFDoc::markObject (Object* obj, XRef *xRef, XRef *countRef, unsigned int n
case objArray:
array = obj->getArray();
for (int i=0; i<array->getLength(); i++) {
Object obj1 = array->getNF(i);
Object obj1 = array->getNF(i).copy();
markObject(&obj1, xRef, countRef, numOffset, oldRefNum, newRefNum);
}
break;
......@@ -1784,7 +1784,7 @@ void PDFDoc::markPageObjects(Dict *pageDict, XRef *xRef, XRef *countRef, unsigne
for (int n = 0; n < pageDict->getLength(); n++) {
const char *key = pageDict->getKey(n);
Object value = pageDict->getValNF(n);
Object value = pageDict->getValNF(n).copy();
if (strcmp(key, "Parent") != 0 &&
strcmp(key, "Pages") != 0 &&
strcmp(key, "AcroForm") != 0 &&
......@@ -1810,7 +1810,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
Object obj2 = dict->lookupNF("P");
if (obj2.isRef()) {
if (obj2.getRef().num == oldPageNum) {
Object obj3 = array->getNF(i);
const Object &obj3 = array->getNF(i);
if (obj3.isRef()) {
Ref r;
r.num = newPageNum;
......@@ -1837,7 +1837,7 @@ bool PDFDoc::markAnnotations(Object *annotsObj, XRef *xRef, XRef *countRef, unsi
}
markPageObjects(dict, xRef, countRef, numOffset, oldPageNum, newPageNum, alreadyMarkedDicts);
}
obj1 = array->getNF(i);
obj1 = array->getNF(i).copy();
if (obj1.isRef()) {
if (obj1.getRef().num + (int) numOffset >= xRef->getNumObjects() || xRef->getEntry(obj1.getRef().num + numOffset)->type == xrefEntryFree) {
if (getXRef()->getEntry(obj1.getRef().num)->type == xrefEntryFree) {
......@@ -1889,10 +1889,10 @@ void PDFDoc::markAcroForm(Object *afObj, XRef *xRef, XRef *countRef, unsigned in
Dict *dict = acroform.getDict();
for (int i=0; i < dict->getLength(); i++) {
if (strcmp(dict->getKey(i), "Fields") == 0) {
Object fields = dict->getValNF(i);
Object fields = dict->getValNF(i).copy();
modified = markAnnotations(&fields, xRef, countRef, numOffset, oldRefNum, newRefNum);
} else {
Object obj = dict->getValNF(i);
Object obj = dict->getValNF(i).copy();
markObject(&obj, xRef, countRef, numOffset, oldRefNum, newRefNum);
}
}
......
......@@ -1791,7 +1791,7 @@ void PSOutputDev::setupResources(Dict *resDict) {
// avoid infinite recursion on XObjects
skip = false;
Object xObjRef = xObjDict.dictGetValNF(i);
const Object &xObjRef = xObjDict.dictGetValNF(i);
if (xObjRef.isRef()) {
Ref ref0 = xObjRef.getRef();
if (resourceIDs.find(ref0.num) != resourceIDs.end()) {
......@@ -1822,7 +1822,7 @@ void PSOutputDev::setupResources(Dict *resDict) {
// avoid infinite recursion on Patterns
skip = false;
Object patRef = patDict.dictGetValNF(i);
const Object &patRef = patDict.dictGetValNF(i);
if (patRef.isRef()) {
Ref ref0 = patRef.getRef();
if (resourceIDs.find(ref0.num) != resourceIDs.end()) {
......@@ -2893,7 +2893,7 @@ void PSOutputDev::setupImages(Dict *resDict) {
Object xObjDict = resDict->lookup("XObject");
if (xObjDict.isDict()) {
for (int i = 0; i < xObjDict.dictGetLength(); ++i) {
Object xObjRef = xObjDict.dictGetValNF(i);
const Object &xObjRef = xObjDict.dictGetValNF(i);
Object xObj = xObjDict.dictGetVal(i);
if (xObj.isStream()) {
Object subtypeObj = xObj.streamGetDict()->lookup("Subtype");
......@@ -3110,7 +3110,7 @@ void PSOutputDev::setupForms(Dict *resDict) {
Object xObjDict = resDict->lookup("XObject");
if (xObjDict.isDict()) {
for (int i = 0; i < xObjDict.dictGetLength(); ++i) {
Object xObjRef = xObjDict.dictGetValNF(i);
const Object &xObjRef = xObjDict.dictGetValNF(i);
Object xObj = xObjDict.dictGetVal(i);
if (xObj.isStream()) {
Object subtypeObj = xObj.streamGetDict()->lookup("Subtype");
......
......@@ -423,7 +423,7 @@ void Page::removeAnnot(Annot *annot) {
int idx = -1;
// Get annotation position
for (int i = 0; idx == -1 && i < annArray.arrayGetLength(); ++i) {
Object tmp = annArray.arrayGetNF(i);
const Object &tmp = annArray.arrayGetNF(i);
if (tmp.isRef()) {
Ref currAnnot = tmp.getRef();
if (currAnnot.num == annotRef.num && currAnnot.gen == annotRef.gen) {
......
......@@ -6,7 +6,7 @@
//
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Luigi Scarso <luigi.scarso@gmail.com>
// Copyright 2014, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright 2014, 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright 2015 Dmytro Morgun <lztoad@gmail.com>
// Copyright 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
......@@ -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);
Object ref = kids.arrayGetNF(i).copy();
parseChild(&ref, &obj, seen);
}
} else if (kids.isDict() || kids.isInt()) {
......
......@@ -7,7 +7,7 @@
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright 2017 Jan-Erik S <janerik234678@gmail.com>
// Copyright 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright 2017, 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright 2018, Adam Reichold <adam.reichold@t-online.de>
//
......@@ -65,7 +65,7 @@ void StructTreeRoot::parse(Dict *root)
error(errSyntaxWarning, -1, "K in StructTreeRoot has more than one children in a tagged PDF");
}
for (int i = 0; i < kids.arrayGetLength(); i++) {
Object ref = kids.arrayGetNF(i);
const Object &ref = kids.arrayGetNF(i);
if (ref.isRef()) {
seenElements.insert(ref.getRefNum());
}
......@@ -145,7 +145,7 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
if (value.isArray()) {
vec.resize(value.arrayGetLength());
for (int j = 0; j < value.arrayGetLength(); j++) {
Object itemvalue = value.arrayGetNF(j);
const Object &itemvalue = value.arrayGetNF(j);
if (itemvalue.isRef()) {
Ref ref = itemvalue.getRef();
vec[j].ref = ref;
......@@ -155,7 +155,7 @@ void StructTreeRoot::parseNumberTreeNode(Dict *node)
}
}
} else {
value = nums.arrayGetNF(i + 1);
value = nums.arrayGetNF(i + 1).copy();
if (value.isRef()) {
Ref ref = value.getRef();
vec.resize(1);
......
......@@ -1617,7 +1617,7 @@ void XRef::markUnencrypted(Object *obj) {
{
Array *array = obj->getArray();
for (int i = 0; i < array->getLength(); i++) {
obj1 = array->getNF(i);
obj1 = array->getNF(i).copy();
markUnencrypted(&obj1);
}
break;
......@@ -1633,7 +1633,7 @@ void XRef::markUnencrypted(Object *obj) {
dict = obj->getDict();
}
for (int i = 0; i < dict->getLength(); i++) {
obj1 = dict->getValNF(i);
obj1 = dict->getValNF(i).copy();
markUnencrypted(&obj1);
}
break;
......
......@@ -3,7 +3,7 @@
* Copyright (C) 2007, Brad Hards <bradh@kde.org>
* Copyright (C) 2008, 2014, Pino Toscano <pino@kde.org>
* Copyright (C) 2008, Carlos Garcia Campos <carlosgc@gnome.org>
* Copyright (C) 2015-2018, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2015-2019, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2017, Hubert Figuière <hub@figuiere.net>
* Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
* Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
......@@ -43,7 +43,7 @@ namespace Poppler
{
itemsInGroup.reserve(rbarray->getLength());
for (int i = 0; i < rbarray->getLength(); ++i) {
Object ref = rbarray->getNF( i );
const Object &ref = rbarray->getNF( i );
if ( ! ref.isRef() ) {
qDebug() << "expected ref, but got:" << ref.getType();
}
......@@ -201,7 +201,7 @@ namespace Poppler
for (int i = 0; i < orderArray->getLength(); ++i) {
Object orderItem = orderArray->get(i);
if ( orderItem.isDict() ) {
Object item = orderArray->getNF(i);
const Object &item = orderArray->getNF(i);
if (item.isRef() ) {
OptContentItem *ocItem = m_optContentItems.value(QString::number(item.getRefNum()));
if (ocItem) {
......
......@@ -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);
Object valB = dictB->lookupNF(key);
Object valA = dictA->getValNF(i).copy();
Object valB = dictB->lookupNF(key).copy();
if (!compareObjects(&valA, &valB))
return false;
}
......@@ -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);
Object elemB = arrayB->getNF(i);
Object elemA = arrayA->getNF(i).copy();