Commit a1b7baea authored by Albert Astals Cid's avatar Albert Astals Cid

Annot: save some unneeded copy() calls

parent c33a0e82
...@@ -929,7 +929,7 @@ int AnnotAppearance::getNumStates() { ...@@ -929,7 +929,7 @@ int AnnotAppearance::getNumStates() {
} }
// Test if stateObj (a Ref or a Dict) points to the specified stream // Test if stateObj (a Ref or a Dict) points to the specified stream
bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) { bool AnnotAppearance::referencesStream(const Object *stateObj, Ref refToStream) {
if (stateObj->isRef()) { if (stateObj->isRef()) {
Ref r = stateObj->getRef(); Ref r = stateObj->getRef();
if (r.num == refToStream.num && r.gen == refToStream.gen) { if (r.num == refToStream.num && r.gen == refToStream.gen) {
...@@ -952,22 +952,21 @@ bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) { ...@@ -952,22 +952,21 @@ bool AnnotAppearance::referencesStream(Object *stateObj, Ref refToStream) {
// Test if this AnnotAppearance references the specified stream // Test if this AnnotAppearance references the specified stream
bool AnnotAppearance::referencesStream(Ref refToStream) { bool AnnotAppearance::referencesStream(Ref refToStream) {
Object obj1;
bool found; bool found;
// Scan each state's ref/subdictionary // Scan each state's ref/subdictionary
obj1 = appearDict.dictLookupNF("N").copy(); const Object &objN = appearDict.dictLookupNF("N");
found = referencesStream(&obj1, refToStream); found = referencesStream(&objN, refToStream);
if (found) if (found)
return true; return true;
obj1 = appearDict.dictLookupNF("R").copy(); const Object &objR = appearDict.dictLookupNF("R");
found = referencesStream(&obj1, refToStream); found = referencesStream(&objR, refToStream);
if (found) if (found)
return true; return true;
obj1 = appearDict.dictLookupNF("D").copy(); const Object &objD = appearDict.dictLookupNF("D");
found = referencesStream(&obj1, refToStream); found = referencesStream(&objD, refToStream);
return found; return found;
} }
...@@ -995,7 +994,7 @@ void AnnotAppearance::removeStream(Ref refToStream) { ...@@ -995,7 +994,7 @@ void AnnotAppearance::removeStream(Ref refToStream) {
} }
// Removes stream if obj is a Ref, or removes pointed streams if obj is a Dict // Removes stream if obj is a Ref, or removes pointed streams if obj is a Dict
void AnnotAppearance::removeStateStreams(Object *obj1) { void AnnotAppearance::removeStateStreams(const Object *obj1) {
if (obj1->isRef()) { if (obj1->isRef()) {
removeStream(obj1->getRef()); removeStream(obj1->getRef());
} else if (obj1->isDict()) { } else if (obj1->isDict()) {
...@@ -1010,13 +1009,12 @@ void AnnotAppearance::removeStateStreams(Object *obj1) { ...@@ -1010,13 +1009,12 @@ void AnnotAppearance::removeStateStreams(Object *obj1) {
} }
void AnnotAppearance::removeAllStreams() { void AnnotAppearance::removeAllStreams() {
Object obj1; const Object &objN = appearDict.dictLookupNF("N");
obj1 = appearDict.dictLookupNF("N").copy(); removeStateStreams(&objN);
removeStateStreams(&obj1); const Object &objR = appearDict.dictLookupNF("R");
obj1 = appearDict.dictLookupNF("R").copy(); removeStateStreams(&objR);
removeStateStreams(&obj1); const Object &objD = appearDict.dictLookupNF("D");
obj1 = appearDict.dictLookupNF("D").copy(); removeStateStreams(&objD);
removeStateStreams(&obj1);
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
// Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com> // Copyright (C) 2008 Hugo Mercier <hmercier31@gmail.com>
// Copyright (C) 2008 Pino Toscano <pino@kde.org> // Copyright (C) 2008 Pino Toscano <pino@kde.org>
// Copyright (C) 2008 Tomas Are Haavet <tomasare@gmail.com> // Copyright (C) 2008 Tomas Are Haavet <tomasare@gmail.com>
// Copyright (C) 2009-2011, 2013, 2016-2018 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2009-2011, 2013, 2016-2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it> // Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2012, 2015 Tobias Koenig <tokoe@kdab.com> // Copyright (C) 2012, 2015 Tobias Koenig <tokoe@kdab.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
...@@ -446,9 +446,9 @@ public: ...@@ -446,9 +446,9 @@ public:
bool referencesStream(Ref targetStreamRef); bool referencesStream(Ref targetStreamRef);
private: private:
static bool referencesStream(Object *stateObj, Ref targetStreamRef); static bool referencesStream(const Object *stateObj, Ref targetStreamRef);
void removeStream(Ref refToStream); void removeStream(Ref refToStream);
void removeStateStreams(Object *state); void removeStateStreams(const Object *state);
protected: protected:
PDFDoc *doc; PDFDoc *doc;
......
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