[poppler] poppler/Array.cc poppler/Array.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Sep 22 21:49:58 UTC 2018
poppler/Array.cc | 39 ++++++++++-----------------------------
poppler/Array.h | 7 +++----
2 files changed, 13 insertions(+), 33 deletions(-)
New commits:
commit ab04ccdd0d78ecf50f50b0458468788aa3984bcc
Author: Adam Reichold <adam.reichold at t-online.de>
Date: Tue May 15 19:49:58 2018 +0200
Also simplify the Array implementation by rebasing it on std::vector<Object>.
diff --git a/poppler/Array.cc b/poppler/Array.cc
index 33f6e458..24d863da 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -31,10 +31,8 @@
#pragma implementation
#endif
-#include <stdlib.h>
-#include <stddef.h>
#include <cassert>
-#include "goo/gmem.h"
+
#include "Object.h"
#include "Array.h"
@@ -46,62 +44,45 @@
Array::Array(XRef *xrefA) {
xref = xrefA;
- elems = nullptr;
- size = length = 0;
ref = 1;
}
Array::~Array() {
- int i;
-
- for (i = 0; i < length; ++i)
- elems[i].free();
- gfree(elems);
}
Object Array::copy(XRef *xrefA) const {
arrayLocker();
Array *a = new Array(xrefA);
- for (int i = 0; i < length; ++i) {
- a->add(elems[i].copy());
+ a->elems.reserve(elems.size());
+ for (const auto& elem : elems) {
+ a->elems.push_back(elem.copy());
}
return Object(a);
}
void Array::add(Object &&elem) {
arrayLocker();
- if (length == size) {
- if (length == 0) {
- size = 8;
- } else {
- size *= 2;
- }
- elems = (Object *)greallocn(elems, size, sizeof(Object));
- }
- elems[length].initNullAfterMalloc();
- elems[length] = std::move(elem);
- ++length;
+ elems.push_back(std::move(elem));
}
void Array::remove(int i) {
arrayLocker();
- if (i < 0 || i >= length) {
- assert(i >= 0 && i < length);
+ if (i < 0 || std::size_t(i) >= elems.size()) {
+ assert(i >= 0 && std::size_t(i) < elems.size());
return;
}
- --length;
- memmove( static_cast<void*>(elems + i), elems + i + 1, sizeof(elems[0]) * (length - i) );
+ elems.erase(elems.begin() + i);
}
Object Array::get(int i, int recursion) const {
- if (i < 0 || i >= length) {
+ if (i < 0 || std::size_t(i) >= elems.size()) {
return Object(objNull);
}
return elems[i].fetch(xref, recursion);
}
Object Array::getNF(int i) const {
- if (i < 0 || i >= length) {
+ if (i < 0 || std::size_t(i) >= elems.size()) {
return Object(objNull);
}
return elems[i].copy();
diff --git a/poppler/Array.h b/poppler/Array.h
index ff8755cf..bfb24170 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -33,6 +33,7 @@
#include <atomic>
#include <mutex>
+#include <vector>
#include "poppler-config.h"
#include "Object.h"
@@ -56,7 +57,7 @@ public:
Array& operator=(const Array &) = delete;
// Get number of elements.
- int getLength() const { return length; }
+ int getLength() const { return elems.size(); }
// Copy array with new xref
Object copy(XRef *xrefA) const;
@@ -81,9 +82,7 @@ private:
int decRef() { return --ref; }
XRef *xref; // the xref table for this PDF file
- Object *elems; // array of elements
- int size; // size of <elems> array
- int length; // number of elements in array
+ std::vector<Object> elems; // array of elements
std::atomic_int ref; // reference count
mutable std::recursive_mutex mutex;
};
More information about the poppler
mailing list