Commit cedb37caa153abfd92a91b2e39a6f32601be826c

Authored by m-holger
1 parent c6179da9

Refactor QPDF_Array::appendItem and rename to push_back

libqpdf/QPDFObjectHandle.cc
... ... @@ -951,10 +951,8 @@ QPDFObjectHandle::insertItemAndGetNew(int at, QPDFObjectHandle const& item)
951 951 void
952 952 QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
953 953 {
954   - auto array = asArray();
955   - if (array) {
956   - checkOwnership(item);
957   - array->appendItem(item);
  954 + if (auto array = asArray()) {
  955 + array->push_back(item);
958 956 } else {
959 957 typeWarning("array", "ignoring attempt to append item");
960 958 QTC::TC("qpdf", "QPDFObjectHandle array ignoring append item");
... ...
libqpdf/QPDF_Array.cc
... ... @@ -264,10 +264,11 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
264 264 }
265 265  
266 266 void
267   -QPDF_Array::appendItem(QPDFObjectHandle const& item)
  267 +QPDF_Array::push_back(QPDFObjectHandle const& item)
268 268 {
  269 + checkOwnership(item);
269 270 if (sparse) {
270   - sp_elements.append(item);
  271 + sp_elements.elements[sp_elements.n_elements++] = item.getObj();
271 272 } else {
272 273 elements.push_back(item.getObj());
273 274 }
... ...
libqpdf/SparseOHArray.cc
... ... @@ -4,24 +4,6 @@
4 4  
5 5 static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull();
6 6  
7   -void
8   -SparseOHArray::append(QPDFObjectHandle oh)
9   -{
10   - if (!oh.isDirectNull()) {
11   - this->elements[this->n_elements] = oh.getObj();
12   - }
13   - ++this->n_elements;
14   -}
15   -
16   -void
17   -SparseOHArray::append(std::shared_ptr<QPDFObject>&& obj)
18   -{
19   - if (obj->getTypeCode() != ::ot_null || !obj->getObjGen().isIndirect()) {
20   - this->elements[this->n_elements] = std::move(obj);
21   - }
22   - ++this->n_elements;
23   -}
24   -
25 7 QPDFObjectHandle
26 8 SparseOHArray::at(int idx) const
27 9 {
... ...
libqpdf/qpdf/QPDF_Array.hh
... ... @@ -34,7 +34,7 @@ class QPDF_Array: public QPDFValue
34 34 void setFromVector(std::vector<QPDFObjectHandle> const& items);
35 35 void setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& items);
36 36 void insertItem(int at, QPDFObjectHandle const& item);
37   - void appendItem(QPDFObjectHandle const& item);
  37 + void push_back(QPDFObjectHandle const& item);
38 38 void eraseItem(int at);
39 39  
40 40 private:
... ...
libqpdf/qpdf/SparseOHArray.hh
... ... @@ -16,8 +16,16 @@ class SparseOHArray
16 16 {
17 17 return n_elements;
18 18 }
19   - void append(QPDFObjectHandle oh);
20   - void append(std::shared_ptr<QPDFObject>&& obj);
  19 + void
  20 + append(QPDFObjectHandle oh)
  21 + {
  22 + elements[n_elements++] = oh.getObj();
  23 + }
  24 + void
  25 + append(std::shared_ptr<QPDFObject>&& obj)
  26 + {
  27 + elements[n_elements++] = std::move(obj);
  28 + }
21 29 QPDFObjectHandle at(int idx) const;
22 30 void remove_last();
23 31 void setAt(int idx, QPDFObjectHandle oh);
... ...