2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-23 11:28:56 +00:00

Shallow copy arrays without removing sparseness

This commit is contained in:
Jay Berkenbilt 2019-08-17 22:27:55 -04:00
parent bf7c6a8070
commit 5187a3ec85
3 changed files with 12 additions and 1 deletions

View File

@ -2340,7 +2340,10 @@ QPDFObjectHandle::shallowCopy()
if (isArray()) if (isArray())
{ {
QTC::TC("qpdf", "QPDFObjectHandle shallow copy array"); QTC::TC("qpdf", "QPDFObjectHandle shallow copy array");
new_obj = newArray(getArrayAsVector()); // No newArray for shallow copying the sparse array
QPDF_Array* arr = dynamic_cast<QPDF_Array*>(m->obj.getPointer());
new_obj = QPDFObjectHandle(
new QPDF_Array(arr->getElementsForShallowCopy()));
} }
else if (isDictionary()) else if (isDictionary())
{ {

View File

@ -136,3 +136,9 @@ QPDF_Array::eraseItem(int at)
{ {
this->elements.erase(QIntC::to_size(at)); this->elements.erase(QIntC::to_size(at));
} }
SparseOHArray const&
QPDF_Array::getElementsForShallowCopy() const
{
return this->elements;
}

View File

@ -28,6 +28,8 @@ class QPDF_Array: public QPDFObject
void appendItem(QPDFObjectHandle const& item); void appendItem(QPDFObjectHandle const& item);
void eraseItem(int at); void eraseItem(int at);
SparseOHArray const& getElementsForShallowCopy() const;
protected: protected:
virtual void releaseResolved(); virtual void releaseResolved();