diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 5 | ||||
-rw-r--r-- | libqpdf/QPDF_Array.cc | 16 | ||||
-rw-r--r-- | libqpdf/qpdf/QPDF_Array.hh | 2 |
3 files changed, 13 insertions, 10 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 396e2063..20be3f9d 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -888,15 +888,14 @@ QPDFObjectHandle::getArrayAsMatrix() std::vector<QPDFObjectHandle> QPDFObjectHandle::getArrayAsVector() { - std::vector<QPDFObjectHandle> result; auto array = asArray(); if (array) { - array->getAsVector(result); + return array->getAsVector(); } else { typeWarning("array", "treating as empty"); QTC::TC("qpdf", "QPDFObjectHandle array treating as empty vector"); } - return result; + return {}; } // Array mutators diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 3ed18bf4..9593c31f 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -172,16 +172,20 @@ QPDF_Array::at(int n) const noexcept } } -void -QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const +std::vector<QPDFObjectHandle> +QPDF_Array::getAsVector() const { if (sparse) { - int size = sp_elements.size(); - for (int i = 0; i < size; ++i) { - v.push_back(at(i)); + std::vector<QPDFObjectHandle> v; + v.reserve(size_t(size())); + for (auto const& item: sp_elements.elements) { + v.resize(size_t(item.first), null_oh); + v.push_back(item.second); } + v.resize(size_t(size()), null_oh); + return v; } else { - v = std::vector<QPDFObjectHandle>(elements.cbegin(), elements.cend()); + return {elements.cbegin(), elements.cend()}; } } diff --git a/libqpdf/qpdf/QPDF_Array.hh b/libqpdf/qpdf/QPDF_Array.hh index f4d1fc3d..df814d74 100644 --- a/libqpdf/qpdf/QPDF_Array.hh +++ b/libqpdf/qpdf/QPDF_Array.hh @@ -29,7 +29,7 @@ class QPDF_Array: public QPDFValue } QPDFObjectHandle at(int n) const noexcept; bool setAt(int n, QPDFObjectHandle const& oh); - void getAsVector(std::vector<QPDFObjectHandle>&) const; + std::vector<QPDFObjectHandle> getAsVector() const; void setFromVector(std::vector<QPDFObjectHandle> const& items); void setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& items); bool insert(int at, QPDFObjectHandle const& item); |