summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2019-11-29 14:54:27 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2019-11-30 00:49:24 +0000
commit82dc60155a015e5798db6f78a5f165dc7dd376c9 (patch)
tree588871bec19c14ecf6cbc0bc0f226533f3615a27
parent1c1d9a70013125f67518f398a2b5abf37ec43cdd (diff)
Turn Links::links into a std::vector instead of **
-rw-r--r--poppler/Link.cc33
-rw-r--r--poppler/Link.h5
2 files changed, 9 insertions, 29 deletions
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