Commit 51d350c98c549ff59dd6423e98d993385f57fa9c

Authored by m-holger
1 parent e6db8dde

Inline QPDF_Array::getNItems and rename to size

libqpdf/QPDFObjectHandle.cc
@@ -789,9 +789,8 @@ QPDFObjectHandle::aitems() @@ -789,9 +789,8 @@ QPDFObjectHandle::aitems()
789 int 789 int
790 QPDFObjectHandle::getArrayNItems() 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 } else { 794 } else {
796 typeWarning("array", "treating as empty"); 795 typeWarning("array", "treating as empty");
797 QTC::TC("qpdf", "QPDFObjectHandle array treating as empty"); 796 QTC::TC("qpdf", "QPDFObjectHandle array treating as empty");
@@ -803,7 +802,7 @@ QPDFObjectHandle @@ -803,7 +802,7 @@ QPDFObjectHandle
803 QPDFObjectHandle::getArrayItem(int n) 802 QPDFObjectHandle::getArrayItem(int n)
804 { 803 {
805 auto array = asArray(); 804 auto array = asArray();
806 - if (array && (n < array->getNItems()) && (n >= 0)) { 805 + if (array && n < array->size() && n >= 0) {
807 return array->getItem(n); 806 return array->getItem(n);
808 } else { 807 } else {
809 if (array) { 808 if (array) {
@@ -823,7 +822,7 @@ bool @@ -823,7 +822,7 @@ bool
823 QPDFObjectHandle::isRectangle() 822 QPDFObjectHandle::isRectangle()
824 { 823 {
825 auto array = asArray(); 824 auto array = asArray();
826 - if ((array == nullptr) || (array->getNItems() != 4)) { 825 + if (array == nullptr || array->size() != 4) {
827 return false; 826 return false;
828 } 827 }
829 for (int i = 0; i < 4; ++i) { 828 for (int i = 0; i < 4; ++i) {
@@ -838,7 +837,7 @@ bool @@ -838,7 +837,7 @@ bool
838 QPDFObjectHandle::isMatrix() 837 QPDFObjectHandle::isMatrix()
839 { 838 {
840 auto array = asArray(); 839 auto array = asArray();
841 - if ((array == nullptr) || (array->getNItems() != 6)) { 840 + if (array == nullptr || array->size() != 6) {
842 return false; 841 return false;
843 } 842 }
844 for (int i = 0; i < 6; ++i) { 843 for (int i = 0; i < 6; ++i) {
@@ -975,7 +974,7 @@ void @@ -975,7 +974,7 @@ void
975 QPDFObjectHandle::eraseItem(int at) 974 QPDFObjectHandle::eraseItem(int at)
976 { 975 {
977 auto array = asArray(); 976 auto array = asArray();
978 - if (array && (at < array->getNItems()) && (at >= 0)) { 977 + if (array && at < array->size() && at >= 0) {
979 array->eraseItem(at); 978 array->eraseItem(at);
980 } else { 979 } else {
981 if (array) { 980 if (array) {
@@ -991,11 +990,9 @@ QPDFObjectHandle::eraseItem(int at) @@ -991,11 +990,9 @@ QPDFObjectHandle::eraseItem(int at)
991 QPDFObjectHandle 990 QPDFObjectHandle
992 QPDFObjectHandle::eraseItemAndGetOld(int at) 991 QPDFObjectHandle::eraseItemAndGetOld(int at)
993 { 992 {
994 - auto result = QPDFObjectHandle::newNull();  
995 auto array = asArray(); 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 eraseItem(at); 996 eraseItem(at);
1000 return result; 997 return result;
1001 } 998 }
@@ -1515,9 +1512,8 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( @@ -1515,9 +1512,8 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
1515 { 1512 {
1516 all_description = description; 1513 all_description = description;
1517 std::vector<QPDFObjectHandle> result; 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 for (int i = 0; i < n_items; ++i) { 1517 for (int i = 0; i < n_items; ++i) {
1522 QPDFObjectHandle item = array->getItem(i); 1518 QPDFObjectHandle item = array->getItem(i);
1523 if (item.isStream()) { 1519 if (item.isStream()) {
@@ -2217,7 +2213,7 @@ QPDFObjectHandle::makeDirect( @@ -2217,7 +2213,7 @@ QPDFObjectHandle::makeDirect(
2217 } else if (isArray()) { 2213 } else if (isArray()) {
2218 std::vector<QPDFObjectHandle> items; 2214 std::vector<QPDFObjectHandle> items;
2219 auto array = asArray(); 2215 auto array = asArray();
2220 - int n = array->getNItems(); 2216 + int n = array->size();
2221 for (int i = 0; i < n; ++i) { 2217 for (int i = 0; i < n; ++i) {
2222 items.push_back(array->getItem(i)); 2218 items.push_back(array->getItem(i));
2223 items.back().makeDirect(visited, stop_at_streams); 2219 items.back().makeDirect(visited, stop_at_streams);
libqpdf/QPDF_Array.cc
@@ -142,18 +142,6 @@ QPDF_Array::getJSON(int json_version) @@ -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 QPDFObjectHandle 145 QPDFObjectHandle
158 QPDF_Array::getItem(int n) const 146 QPDF_Array::getItem(int n) const
159 { 147 {
libqpdf/SparseOHArray.cc
@@ -2,12 +2,6 @@ @@ -2,12 +2,6 @@
2 2
3 #include <stdexcept> 3 #include <stdexcept>
4 4
5 -int  
6 -SparseOHArray::size() const  
7 -{  
8 - return this->n_elements;  
9 -}  
10 -  
11 void 5 void
12 SparseOHArray::append(QPDFObjectHandle oh) 6 SparseOHArray::append(QPDFObjectHandle oh)
13 { 7 {
libqpdf/qpdf/QPDF_Array.hh
@@ -22,7 +22,11 @@ class QPDF_Array: public QPDFValue @@ -22,7 +22,11 @@ class QPDF_Array: public QPDFValue
22 virtual JSON getJSON(int json_version); 22 virtual JSON getJSON(int json_version);
23 virtual void disconnect(); 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 QPDFObjectHandle getItem(int n) const; 30 QPDFObjectHandle getItem(int n) const;
27 void getAsVector(std::vector<QPDFObjectHandle>&) const; 31 void getAsVector(std::vector<QPDFObjectHandle>&) const;
28 32
libqpdf/qpdf/SparseOHArray.hh
@@ -11,7 +11,11 @@ class SparseOHArray @@ -11,7 +11,11 @@ class SparseOHArray
11 { 11 {
12 public: 12 public:
13 SparseOHArray() = default; 13 SparseOHArray() = default;
14 - int size() const; 14 + int
  15 + size() const
  16 + {
  17 + return n_elements;
  18 + }
15 void append(QPDFObjectHandle oh); 19 void append(QPDFObjectHandle oh);
16 void append(std::shared_ptr<QPDFObject>&& obj); 20 void append(std::shared_ptr<QPDFObject>&& obj);
17 QPDFObjectHandle at(int idx) const; 21 QPDFObjectHandle at(int idx) const;