Commit 51d350c98c549ff59dd6423e98d993385f57fa9c
1 parent
e6db8dde
Inline QPDF_Array::getNItems and rename to size
Showing
5 changed files
with
21 additions
and
35 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -789,9 +789,8 @@ QPDFObjectHandle::aitems() |
| 789 | 789 | int |
| 790 | 790 | QPDFObjectHandle::getArrayNItems() |
| 791 | 791 | { |
| 792 | - auto array = asArray(); | |
| 793 | - if (array) { | |
| 794 | - return array->getNItems(); | |
| 792 | + if (auto array = asArray()) { | |
| 793 | + return array->size(); | |
| 795 | 794 | } else { |
| 796 | 795 | typeWarning("array", "treating as empty"); |
| 797 | 796 | QTC::TC("qpdf", "QPDFObjectHandle array treating as empty"); |
| ... | ... | @@ -803,7 +802,7 @@ QPDFObjectHandle |
| 803 | 802 | QPDFObjectHandle::getArrayItem(int n) |
| 804 | 803 | { |
| 805 | 804 | auto array = asArray(); |
| 806 | - if (array && (n < array->getNItems()) && (n >= 0)) { | |
| 805 | + if (array && n < array->size() && n >= 0) { | |
| 807 | 806 | return array->getItem(n); |
| 808 | 807 | } else { |
| 809 | 808 | if (array) { |
| ... | ... | @@ -823,7 +822,7 @@ bool |
| 823 | 822 | QPDFObjectHandle::isRectangle() |
| 824 | 823 | { |
| 825 | 824 | auto array = asArray(); |
| 826 | - if ((array == nullptr) || (array->getNItems() != 4)) { | |
| 825 | + if (array == nullptr || array->size() != 4) { | |
| 827 | 826 | return false; |
| 828 | 827 | } |
| 829 | 828 | for (int i = 0; i < 4; ++i) { |
| ... | ... | @@ -838,7 +837,7 @@ bool |
| 838 | 837 | QPDFObjectHandle::isMatrix() |
| 839 | 838 | { |
| 840 | 839 | auto array = asArray(); |
| 841 | - if ((array == nullptr) || (array->getNItems() != 6)) { | |
| 840 | + if (array == nullptr || array->size() != 6) { | |
| 842 | 841 | return false; |
| 843 | 842 | } |
| 844 | 843 | for (int i = 0; i < 6; ++i) { |
| ... | ... | @@ -975,7 +974,7 @@ void |
| 975 | 974 | QPDFObjectHandle::eraseItem(int at) |
| 976 | 975 | { |
| 977 | 976 | auto array = asArray(); |
| 978 | - if (array && (at < array->getNItems()) && (at >= 0)) { | |
| 977 | + if (array && at < array->size() && at >= 0) { | |
| 979 | 978 | array->eraseItem(at); |
| 980 | 979 | } else { |
| 981 | 980 | if (array) { |
| ... | ... | @@ -991,11 +990,9 @@ QPDFObjectHandle::eraseItem(int at) |
| 991 | 990 | QPDFObjectHandle |
| 992 | 991 | QPDFObjectHandle::eraseItemAndGetOld(int at) |
| 993 | 992 | { |
| 994 | - auto result = QPDFObjectHandle::newNull(); | |
| 995 | 993 | auto array = asArray(); |
| 996 | - if (array && (at < array->getNItems()) && (at >= 0)) { | |
| 997 | - result = array->getItem(at); | |
| 998 | - } | |
| 994 | + auto result = (array && at < array->size() && at >= 0) ? array->getItem(at) | |
| 995 | + : newNull(); | |
| 999 | 996 | eraseItem(at); |
| 1000 | 997 | return result; |
| 1001 | 998 | } |
| ... | ... | @@ -1515,9 +1512,8 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( |
| 1515 | 1512 | { |
| 1516 | 1513 | all_description = description; |
| 1517 | 1514 | std::vector<QPDFObjectHandle> result; |
| 1518 | - auto array = asArray(); | |
| 1519 | - if (array) { | |
| 1520 | - int n_items = array->getNItems(); | |
| 1515 | + if (auto array = asArray()) { | |
| 1516 | + int n_items = array->size(); | |
| 1521 | 1517 | for (int i = 0; i < n_items; ++i) { |
| 1522 | 1518 | QPDFObjectHandle item = array->getItem(i); |
| 1523 | 1519 | if (item.isStream()) { |
| ... | ... | @@ -2217,7 +2213,7 @@ QPDFObjectHandle::makeDirect( |
| 2217 | 2213 | } else if (isArray()) { |
| 2218 | 2214 | std::vector<QPDFObjectHandle> items; |
| 2219 | 2215 | auto array = asArray(); |
| 2220 | - int n = array->getNItems(); | |
| 2216 | + int n = array->size(); | |
| 2221 | 2217 | for (int i = 0; i < n; ++i) { |
| 2222 | 2218 | items.push_back(array->getItem(i)); |
| 2223 | 2219 | items.back().makeDirect(visited, stop_at_streams); | ... | ... |
libqpdf/QPDF_Array.cc
| ... | ... | @@ -142,18 +142,6 @@ QPDF_Array::getJSON(int json_version) |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | -int | |
| 146 | -QPDF_Array::getNItems() const | |
| 147 | -{ | |
| 148 | - if (sparse) { | |
| 149 | - // This should really return a size_t, but changing it would break | |
| 150 | - // a lot of code. | |
| 151 | - return QIntC::to_int(sp_elements.size()); | |
| 152 | - } else { | |
| 153 | - return QIntC::to_int(elements.size()); | |
| 154 | - } | |
| 155 | -} | |
| 156 | - | |
| 157 | 145 | QPDFObjectHandle |
| 158 | 146 | QPDF_Array::getItem(int n) const |
| 159 | 147 | { | ... | ... |
libqpdf/SparseOHArray.cc
libqpdf/qpdf/QPDF_Array.hh
| ... | ... | @@ -22,7 +22,11 @@ class QPDF_Array: public QPDFValue |
| 22 | 22 | virtual JSON getJSON(int json_version); |
| 23 | 23 | virtual void disconnect(); |
| 24 | 24 | |
| 25 | - int getNItems() const; | |
| 25 | + int | |
| 26 | + size() const noexcept | |
| 27 | + { | |
| 28 | + return sparse ? sp_elements.size() : int(elements.size()); | |
| 29 | + } | |
| 26 | 30 | QPDFObjectHandle getItem(int n) const; |
| 27 | 31 | void getAsVector(std::vector<QPDFObjectHandle>&) const; |
| 28 | 32 | ... | ... |
libqpdf/qpdf/SparseOHArray.hh
| ... | ... | @@ -11,7 +11,11 @@ class SparseOHArray |
| 11 | 11 | { |
| 12 | 12 | public: |
| 13 | 13 | SparseOHArray() = default; |
| 14 | - int size() const; | |
| 14 | + int | |
| 15 | + size() const | |
| 16 | + { | |
| 17 | + return n_elements; | |
| 18 | + } | |
| 15 | 19 | void append(QPDFObjectHandle oh); |
| 16 | 20 | void append(std::shared_ptr<QPDFObject>&& obj); |
| 17 | 21 | QPDFObjectHandle at(int idx) const; | ... | ... |