Commit 5187a3ec85f1a83cbde9e77227e215a2dbcfccb0
1 parent
bf7c6a80
Shallow copy arrays without removing sparseness
Showing
3 changed files
with
12 additions
and
1 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -2340,7 +2340,10 @@ QPDFObjectHandle::shallowCopy() | @@ -2340,7 +2340,10 @@ QPDFObjectHandle::shallowCopy() | ||
| 2340 | if (isArray()) | 2340 | if (isArray()) |
| 2341 | { | 2341 | { |
| 2342 | QTC::TC("qpdf", "QPDFObjectHandle shallow copy array"); | 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 | else if (isDictionary()) | 2348 | else if (isDictionary()) |
| 2346 | { | 2349 | { |
libqpdf/QPDF_Array.cc
| @@ -136,3 +136,9 @@ QPDF_Array::eraseItem(int at) | @@ -136,3 +136,9 @@ QPDF_Array::eraseItem(int at) | ||
| 136 | { | 136 | { |
| 137 | this->elements.erase(QIntC::to_size(at)); | 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,6 +28,8 @@ class QPDF_Array: public QPDFObject | ||
| 28 | void appendItem(QPDFObjectHandle const& item); | 28 | void appendItem(QPDFObjectHandle const& item); |
| 29 | void eraseItem(int at); | 29 | void eraseItem(int at); |
| 30 | 30 | ||
| 31 | + SparseOHArray const& getElementsForShallowCopy() const; | ||
| 32 | + | ||
| 31 | protected: | 33 | protected: |
| 32 | virtual void releaseResolved(); | 34 | virtual void releaseResolved(); |
| 33 | 35 |