poppler/Link.cc |   33 +++++++--------------------------
 poppler/Link.h  |    5 ++---
 2 files changed, 9 insertions(+), 29 deletions(-)

New commits:
commit 82dc60155a015e5798db6f78a5f165dc7dd376c9
Author: Albert Astals Cid <aa...@kde.org>
Date:   Fri Nov 29 14:54:27 2019 +0100

    Turn Links::links into a std::vector instead of **

diff --git a/poppler/Link.cc b/poppler/Link.cc
index 64dc7041..4db8fe3d 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -951,44 +951,27 @@ LinkUnknown::~LinkUnknown() {
 //------------------------------------------------------------------------
 
 Links::Links(Annots *annots) {
-  int size;
-  int i;
-
-  links = nullptr;
-  size = 0;
-  numLinks = 0;
-
   if (!annots)
     return;
 
-  for (i = 0; i < annots->getNumAnnots(); ++i) {
+  for (int i = 0; i < annots->getNumAnnots(); ++i) {
     Annot *annot = annots->getAnnot(i);
 
     if (annot->getType() != Annot::typeLink)
       continue;
 
-    if (numLinks >= size) {
-      size += 16;
-      links = (AnnotLink **)greallocn(links, size, sizeof(AnnotLink *));
-    }
     annot->incRefCnt();
-    links[numLinks++] = static_cast<AnnotLink *>(annot);
+    links.push_back(static_cast<AnnotLink *>(annot));
   }
 }
 
 Links::~Links() {
-  int i;
-
-  for (i = 0; i < numLinks; ++i)
-    links[i]->decRefCnt();
-
-  gfree(links);
+  for (AnnotLink *link : links)
+    link->decRefCnt();
 }
 
 LinkAction *Links::find(double x, double y) const {
-  int i;
-
-  for (i = numLinks - 1; i >= 0; --i) {
+  for (int i = getNumLinks() - 1; i >= 0; --i) {
     if (links[i]->inRect(x, y)) {
       return links[i]->getAction();
     }
@@ -997,10 +980,8 @@ LinkAction *Links::find(double x, double y) const {
 }
 
 bool Links::onLink(double x, double y) const {
-  int i;
-
-  for (i = 0; i < numLinks; ++i) {
-    if (links[i]->inRect(x, y))
+  for (AnnotLink *link : links) {
+    if (link->inRect(x, y))
       return true;
   }
   return false;
diff --git a/poppler/Link.h b/poppler/Link.h
index d610fad0..59c1ae0b 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -540,7 +540,7 @@ public:
   Links& operator=(const Links &) = delete;
 
   // Iterate through list of links.
-  int getNumLinks() const { return numLinks; }
+  int getNumLinks() const { return links.size(); }
   AnnotLink *getLink(int i) const { return links[i]; }
 
   // If point <x>,<y> is in a link, return the associated action;
@@ -552,8 +552,7 @@ public:
 
 private:
 
-  AnnotLink **links;
-  int numLinks;
+  std::vector<AnnotLink *> links;
 };
 
 #endif
_______________________________________________
poppler mailing list
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to