poppler/Link.cc | 34 +++++++++++++--------------------- poppler/Link.h | 10 +++++----- qt5/src/poppler-page.cc | 14 +++++--------- 3 files changed, 23 insertions(+), 35 deletions(-)
New commits: commit 80710e99b3d3cb9fe6a05f73f33ed122474c82ae Author: Oliver Sander <[email protected]> Date: Fri Jan 3 17:15:22 2020 +0100 Make LinkAction::nextActions return a const reference ... rather than a pointer. This makes it clearer that the result is borrowed, and should not be shallow-copied. diff --git a/poppler/Link.cc b/poppler/Link.cc index e8ae73ae..74904acd 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -204,8 +204,8 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI, return action; } -const std::vector<LinkAction*> *LinkAction::nextActions() const { - return &nextActionList; +const std::vector<LinkAction*>& LinkAction::nextActions() const { + return nextActionList; } void LinkAction::setNextActions(std::vector<LinkAction*>&& actions) { diff --git a/poppler/Link.h b/poppler/Link.h index 86b74b51..b6fb9fb4 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -85,7 +85,7 @@ public: // A List of the next actions to execute in order. // The list contains pointer to LinkAction objects. - const std::vector<LinkAction*> *nextActions() const; + const std::vector<LinkAction*>& nextActions() const; // Sets the next action list. void setNextActions(std::vector<LinkAction*>&& actions); diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index c9987761..29394d20 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -17,7 +17,7 @@ * Copyright (C) 2015 William Bader <[email protected]> * Copyright (C) 2016 Arseniy Lartsev <[email protected]> * Copyright (C) 2016, Hanno Meyer-Thurow <[email protected]> - * Copyright (C) 2017-2019, Oliver Sander <[email protected]> + * Copyright (C) 2017-2020, Oliver Sander <[email protected]> * Copyright (C) 2017 Adrian Johnson <[email protected]> * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich * Copyright (C) 2018 Intevation GmbH <[email protected]> @@ -360,16 +360,12 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo if ( popplerLink ) { - const std::vector<::LinkAction*> *nextActions = a->nextActions(); - if ( nextActions ) + QVector<Link *> links; + for ( ::LinkAction *nextAction : a->nextActions() ) { - QVector<Link *> links; - for ( ::LinkAction *nextAction : *nextActions ) - { - links << convertLinkActionToLink( nextAction, parentDoc, linkArea ); - } - LinkPrivate::get(popplerLink)->nextLinks = links; + links << convertLinkActionToLink( nextAction, parentDoc, linkArea ); } + LinkPrivate::get(popplerLink)->nextLinks = links; } return popplerLink; commit 1239f2dc9c621e6a1962a7ebe0cced9c333c202c Author: Oliver Sander <[email protected]> Date: Fri Jan 3 17:10:02 2020 +0100 Make LinkAction::nextActionList a std::vector Rather than a pointer to a std::vector. This removes one layer of indirection when accessing the vector. diff --git a/poppler/Link.cc b/poppler/Link.cc index a25037ae..e8ae73ae 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -23,7 +23,7 @@ // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Intevation GmbH <[email protected]> // Copyright (C) 2018 Adam Reichold <[email protected]> -// Copyright (C) 2019 Oliver Sander <[email protected]> +// Copyright (C) 2019, 2020 Oliver Sander <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -49,15 +49,11 @@ //------------------------------------------------------------------------ // LinkAction //------------------------------------------------------------------------ -LinkAction::LinkAction() : nextActionList(nullptr) { -} +LinkAction::LinkAction() = default; LinkAction::~LinkAction() { - if (nextActionList) { - for (auto entry : *nextActionList) { - delete entry; - } - delete nextActionList; + for (auto entry : nextActionList) { + delete entry; } } @@ -162,7 +158,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI, // parse the next actions const Object nextObj = obj->dictLookup("Next"); - std::vector<LinkAction*> *actionList = nullptr; + std::vector<LinkAction*> actionList; if (nextObj.isDict()) { // Prevent circles in the tree by checking the ref against used refs in @@ -176,14 +172,12 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI, } } - actionList = new std::vector<LinkAction*>(); - actionList->reserve(1); - actionList->push_back(parseAction(&nextObj, nullptr, seenNextActions)); + actionList.reserve(1); + actionList.push_back(parseAction(&nextObj, nullptr, seenNextActions)); } else if (nextObj.isArray()) { const Array *a = nextObj.getArray(); const int n = a->getLength(); - actionList = new std::vector<LinkAction*>(); - actionList->reserve(n); + actionList.reserve(n); for (int i = 0; i < n; ++i) { const Object obj3 = a->get(i); if (!obj3.isDict()) { @@ -197,27 +191,25 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI, const Ref ref = obj3Ref.getRef(); if (!seenNextActions->insert(ref.num).second) { error(errSyntaxWarning, -1, "parseAction: Circular next actions detected in array."); - delete actionList; return action; } } - actionList->push_back(parseAction(&obj3, nullptr, seenNextActions)); + actionList.push_back(parseAction(&obj3, nullptr, seenNextActions)); } } - action->setNextActions(actionList); + action->setNextActions(std::move(actionList)); return action; } const std::vector<LinkAction*> *LinkAction::nextActions() const { - return nextActionList; + return &nextActionList; } -void LinkAction::setNextActions(std::vector<LinkAction*> *actions) { - delete nextActionList; - nextActionList = actions; +void LinkAction::setNextActions(std::vector<LinkAction*>&& actions) { + nextActionList = std::move(actions); } //------------------------------------------------------------------------ diff --git a/poppler/Link.h b/poppler/Link.h index 4477dd3f..86b74b51 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -20,7 +20,7 @@ // Copyright (C) 2018, 2019 Albert Astals Cid <[email protected]> // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Intevation GmbH <[email protected]> -// Copyright (C) 2019 Oliver Sander <[email protected]> +// Copyright (C) 2019, 2020 Oliver Sander <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -87,13 +87,13 @@ public: // The list contains pointer to LinkAction objects. const std::vector<LinkAction*> *nextActions() const; - // Sets the next action list. Takes ownership of the actions. - void setNextActions(std::vector<LinkAction*> *actions); + // Sets the next action list. + void setNextActions(std::vector<LinkAction*>&& actions); private: static LinkAction *parseAction(const Object *obj, const GooString *baseURI, std::set<int> *seenNextActions); - std::vector<LinkAction*> *nextActionList; + std::vector<LinkAction*> nextActionList; }; //------------------------------------------------------------------------ _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
