Commit 5187a3ec85f1a83cbde9e77227e215a2dbcfccb0

Authored by Jay Berkenbilt
1 parent bf7c6a80

Shallow copy arrays without removing sparseness

libqpdf/QPDFObjectHandle.cc
... ... @@ -2340,7 +2340,10 @@ QPDFObjectHandle::shallowCopy()
2340 2340 if (isArray())
2341 2341 {
2342 2342 QTC::TC("qpdf", "QPDFObjectHandle shallow copy array");
2343   - new_obj = newArray(getArrayAsVector());
  2343 + // No newArray for shallow copying the sparse array
  2344 + QPDF_Array* arr = dynamic_cast<QPDF_Array*>(m->obj.getPointer());
  2345 + new_obj = QPDFObjectHandle(
  2346 + new QPDF_Array(arr->getElementsForShallowCopy()));
2344 2347 }
2345 2348 else if (isDictionary())
2346 2349 {
... ...
libqpdf/QPDF_Array.cc
... ... @@ -136,3 +136,9 @@ QPDF_Array::eraseItem(int at)
136 136 {
137 137 this->elements.erase(QIntC::to_size(at));
138 138 }
  139 +
  140 +SparseOHArray const&
  141 +QPDF_Array::getElementsForShallowCopy() const
  142 +{
  143 + return this->elements;
  144 +}
... ...
libqpdf/qpdf/QPDF_Array.hh
... ... @@ -28,6 +28,8 @@ class QPDF_Array: public QPDFObject
28 28 void appendItem(QPDFObjectHandle const& item);
29 29 void eraseItem(int at);
30 30  
  31 + SparseOHArray const& getElementsForShallowCopy() const;
  32 +
31 33 protected:
32 34 virtual void releaseResolved();
33 35  
... ...