[poppler] 2 commits - poppler/Link.cc poppler/Link.h qt5/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 3 22:27:16 UTC 2020


 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 <oliver.sander at tu-dresden.de>
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 <williambader at hotmail.com>
  * Copyright (C) 2016 Arseniy Lartsev <arseniy at alumni.chalmers.se>
  * Copyright (C) 2016, Hanno Meyer-Thurow <h.mth at web.de>
- * Copyright (C) 2017-2019, Oliver Sander <oliver.sander at tu-dresden.de>
+ * Copyright (C) 2017-2020, Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
  * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
  * Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
@@ -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 <oliver.sander at tu-dresden.de>
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, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
 // Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
 // Copyright (C) 2018 Adam Reichold <adam.reichold at t-online.de>
-// Copyright (C) 2019 Oliver Sander <oliver.sander at tu-dresden.de>
+// Copyright (C) 2019, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
 //
 // 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 <aacid at kde.org>
 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
 // Copyright (C) 2018 Intevation GmbH <intevation at intevation.de>
-// Copyright (C) 2019 Oliver Sander <oliver.sander at tu-dresden.de>
+// Copyright (C) 2019, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
 //
 // 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;
 };
 
 //------------------------------------------------------------------------


More information about the poppler mailing list