2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Refactor QPDF_Array::appendItem and rename to push_back

This commit is contained in:
m-holger 2022-12-10 19:05:12 +00:00
parent c6179da961
commit cedb37caa1
5 changed files with 16 additions and 27 deletions

View File

@ -951,10 +951,8 @@ QPDFObjectHandle::insertItemAndGetNew(int at, QPDFObjectHandle const& item)
void
QPDFObjectHandle::appendItem(QPDFObjectHandle const& item)
{
auto array = asArray();
if (array) {
checkOwnership(item);
array->appendItem(item);
if (auto array = asArray()) {
array->push_back(item);
} else {
typeWarning("array", "ignoring attempt to append item");
QTC::TC("qpdf", "QPDFObjectHandle array ignoring append item");

View File

@ -264,10 +264,11 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
}
void
QPDF_Array::appendItem(QPDFObjectHandle const& item)
QPDF_Array::push_back(QPDFObjectHandle const& item)
{
checkOwnership(item);
if (sparse) {
sp_elements.append(item);
sp_elements.elements[sp_elements.n_elements++] = item.getObj();
} else {
elements.push_back(item.getObj());
}

View File

@ -4,24 +4,6 @@
static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull();
void
SparseOHArray::append(QPDFObjectHandle oh)
{
if (!oh.isDirectNull()) {
this->elements[this->n_elements] = oh.getObj();
}
++this->n_elements;
}
void
SparseOHArray::append(std::shared_ptr<QPDFObject>&& obj)
{
if (obj->getTypeCode() != ::ot_null || !obj->getObjGen().isIndirect()) {
this->elements[this->n_elements] = std::move(obj);
}
++this->n_elements;
}
QPDFObjectHandle
SparseOHArray::at(int idx) const
{

View File

@ -34,7 +34,7 @@ class QPDF_Array: public QPDFValue
void setFromVector(std::vector<QPDFObjectHandle> const& items);
void setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& items);
void insertItem(int at, QPDFObjectHandle const& item);
void appendItem(QPDFObjectHandle const& item);
void push_back(QPDFObjectHandle const& item);
void eraseItem(int at);
private:

View File

@ -16,8 +16,16 @@ class SparseOHArray
{
return n_elements;
}
void append(QPDFObjectHandle oh);
void append(std::shared_ptr<QPDFObject>&& obj);
void
append(QPDFObjectHandle oh)
{
elements[n_elements++] = oh.getObj();
}
void
append(std::shared_ptr<QPDFObject>&& obj)
{
elements[n_elements++] = std::move(obj);
}
QPDFObjectHandle at(int idx) const;
void remove_last();
void setAt(int idx, QPDFObjectHandle oh);