aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libqpdf/QPDFObjectHandle.cc26
-rw-r--r--libqpdf/QPDF_Array.cc12
-rw-r--r--libqpdf/SparseOHArray.cc6
-rw-r--r--libqpdf/qpdf/QPDF_Array.hh6
-rw-r--r--libqpdf/qpdf/SparseOHArray.hh6
5 files changed, 21 insertions, 35 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index d474dcce..9fd8684b 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -789,9 +789,8 @@ QPDFObjectHandle::aitems()
int
QPDFObjectHandle::getArrayNItems()
{
- auto array = asArray();
- if (array) {
- return array->getNItems();
+ if (auto array = asArray()) {
+ return array->size();
} else {
typeWarning("array", "treating as empty");
QTC::TC("qpdf", "QPDFObjectHandle array treating as empty");
@@ -803,7 +802,7 @@ QPDFObjectHandle
QPDFObjectHandle::getArrayItem(int n)
{
auto array = asArray();
- if (array && (n < array->getNItems()) && (n >= 0)) {
+ if (array && n < array->size() && n >= 0) {
return array->getItem(n);
} else {
if (array) {
@@ -823,7 +822,7 @@ bool
QPDFObjectHandle::isRectangle()
{
auto array = asArray();
- if ((array == nullptr) || (array->getNItems() != 4)) {
+ if (array == nullptr || array->size() != 4) {
return false;
}
for (int i = 0; i < 4; ++i) {
@@ -838,7 +837,7 @@ bool
QPDFObjectHandle::isMatrix()
{
auto array = asArray();
- if ((array == nullptr) || (array->getNItems() != 6)) {
+ if (array == nullptr || array->size() != 6) {
return false;
}
for (int i = 0; i < 6; ++i) {
@@ -975,7 +974,7 @@ void
QPDFObjectHandle::eraseItem(int at)
{
auto array = asArray();
- if (array && (at < array->getNItems()) && (at >= 0)) {
+ if (array && at < array->size() && at >= 0) {
array->eraseItem(at);
} else {
if (array) {
@@ -991,11 +990,9 @@ QPDFObjectHandle::eraseItem(int at)
QPDFObjectHandle
QPDFObjectHandle::eraseItemAndGetOld(int at)
{
- auto result = QPDFObjectHandle::newNull();
auto array = asArray();
- if (array && (at < array->getNItems()) && (at >= 0)) {
- result = array->getItem(at);
- }
+ auto result = (array && at < array->size() && at >= 0) ? array->getItem(at)
+ : newNull();
eraseItem(at);
return result;
}
@@ -1515,9 +1512,8 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
{
all_description = description;
std::vector<QPDFObjectHandle> result;
- auto array = asArray();
- if (array) {
- int n_items = array->getNItems();
+ if (auto array = asArray()) {
+ int n_items = array->size();
for (int i = 0; i < n_items; ++i) {
QPDFObjectHandle item = array->getItem(i);
if (item.isStream()) {
@@ -2217,7 +2213,7 @@ QPDFObjectHandle::makeDirect(
} else if (isArray()) {
std::vector<QPDFObjectHandle> items;
auto array = asArray();
- int n = array->getNItems();
+ int n = array->size();
for (int i = 0; i < n; ++i) {
items.push_back(array->getItem(i));
items.back().makeDirect(visited, stop_at_streams);
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc
index 6568db96..9368ca51 100644
--- a/libqpdf/QPDF_Array.cc
+++ b/libqpdf/QPDF_Array.cc
@@ -142,18 +142,6 @@ QPDF_Array::getJSON(int json_version)
}
}
-int
-QPDF_Array::getNItems() const
-{
- if (sparse) {
- // This should really return a size_t, but changing it would break
- // a lot of code.
- return QIntC::to_int(sp_elements.size());
- } else {
- return QIntC::to_int(elements.size());
- }
-}
-
QPDFObjectHandle
QPDF_Array::getItem(int n) const
{
diff --git a/libqpdf/SparseOHArray.cc b/libqpdf/SparseOHArray.cc
index 7adba00f..3f6376a6 100644
--- a/libqpdf/SparseOHArray.cc
+++ b/libqpdf/SparseOHArray.cc
@@ -2,12 +2,6 @@
#include <stdexcept>
-int
-SparseOHArray::size() const
-{
- return this->n_elements;
-}
-
void
SparseOHArray::append(QPDFObjectHandle oh)
{
diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh
index b52efeb6..558704c7 100644
--- a/libqpdf/qpdf/QPDF_Array.hh
+++ b/libqpdf/qpdf/QPDF_Array.hh
@@ -22,7 +22,11 @@ class QPDF_Array: public QPDFValue
virtual JSON getJSON(int json_version);
virtual void disconnect();
- int getNItems() const;
+ int
+ size() const noexcept
+ {
+ return sparse ? sp_elements.size() : int(elements.size());
+ }
QPDFObjectHandle getItem(int n) const;
void getAsVector(std::vector<QPDFObjectHandle>&) const;
diff --git a/libqpdf/qpdf/SparseOHArray.hh b/libqpdf/qpdf/SparseOHArray.hh
index 191d6915..468e3a39 100644
--- a/libqpdf/qpdf/SparseOHArray.hh
+++ b/libqpdf/qpdf/SparseOHArray.hh
@@ -11,7 +11,11 @@ class SparseOHArray
{
public:
SparseOHArray() = default;
- int size() const;
+ int
+ size() const
+ {
+ return n_elements;
+ }
void append(QPDFObjectHandle oh);
void append(std::shared_ptr<QPDFObject>&& obj);
QPDFObjectHandle at(int idx) const;